GNOME Bugzilla – Bug 633083
SEGFAULT if File is Empty
Last modified: 2016-10-12 11:07:30 UTC
A check if whether current is null needs to be added to "bool comment (bool file_comment = false)" in vala/valageniescanner.vala and a check needs to be added to member "public TokenType read_token (out SourceLocation token_begin, out SourceLocation token_end)" of class "Vala.Genie.Scanner". I will try create a patch later once I work out how to use git. I was able to reproduce this with 0.10.x and the current development snapshot from git.
Created attachment 173158 [details] [review] Patch to fix the bug This fixes the bug. If someone more experienced than me can create a better patch then please do.
Review of attachment 173158 [details] [review]: A simpler solution is possible by checking the mapped file contents are null
Created attachment 337451 [details] [review] Return TokenType.EOF from read_token () if file is empty Vala.SourceFile uses GLib.MappedFile.get_contents () to read the contents of a source file. If that file is empty (zero bytes) then get_contents () returns null. See https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-mapped-file-get-contents This patch adds a check that the pointer to the current position is null and if it is then return an end of file token. The token_begin and token_end are only needed to stop compiler warnings.
Patch looks good. Please apply with help from someone with commit rights on IRC thanks Jamie
commit a4ab6177c9a659b4b76f4fd22aedbb4b22920c55 Author: Alistair Thomas <astavale@yahoo.co.uk> Date: Tue Oct 11 18:28:35 2016 +0100 genie: Add empty file check to read_token () Vala.SourceFile uses GLib.MappedFile.get_contents () to read a source file. This can return null if the file is empty.