The program gives segmentation fault. 

Line 26:
> FILE* file;
> FILE* _tmp1;
> ..............
Line 35:
> file = g_new0 (FILE, 1);
> _tmp1 = NULL;
> (_tmp1 = fopen (filename, "r"));
> (_tmp1 == NULL ? NULL : (_tmp1 = (fclose (_tmp1), NULL)));

I think, the "file = _tmp1" is missed here. The program segfaults at
file.eof().
using GLib;

public class test
{
	static int main (string[] args)
	{
		if (args.length < 2)
		{
			message ("You can specify file (or files) name");
			return 0;
		}
		bool pass = true;
		foreach (string filename in args)
		{
			if (pass)
			{
				pass = false;
				continue;
			}
			FileStream file = new FileStream ();
			file.open (filename, "r");
			char code;
			while (!file.eof())
			{
				code = (char)file.getc();
				stdout.printf (":%c\n", code);
			}
			file.close();
		}
	}
}
#include "test.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

static gint test_main (int args_length1, char** args);


static gint test_main (int args_length1, char** args) {
	gboolean pass;
	if (args_length1 < 2) {
		g_message ("/home/master/Sources/vala-test/test.vala:9: You can specify file (or files) name");
		return 0;
	}
	pass = TRUE;
	{
		char** filename_collection;
		int filename_it;
		filename_collection = args;
		for (filename_it = 0; (args_length1 != -1 && filename_it < args_length1) || (args_length1 == -1 && filename_collection[filename_it] != NULL); filename_it = filename_it + 1) {
			const char* _tmp2;
			char* filename;
			_tmp2 = NULL;
			filename = (_tmp2 = filename_collection[filename_it], (_tmp2 == NULL ? NULL : g_strdup (_tmp2)));
			{
				FILE* file;
				FILE* _tmp1;
				gchar code;
				if (pass) {
					pass = FALSE;
					(filename = (g_free (filename), NULL));
					continue;
				}
				file = g_new0 (FILE, 1);
				_tmp1 = NULL;
				(_tmp1 = fopen (filename, "r"));
				(_tmp1 == NULL ? NULL : (_tmp1 = (fclose (_tmp1), NULL)));
				code = '\0';
				while (!feof (file)) {
					code = ((gchar) fgetc (file));
					fprintf (stdout, ":%c\n", code);
				}
				fclose (file);
				(filename = (g_free (filename), NULL));
				(file == NULL ? NULL : (file = (fclose (file), NULL)));
			}
		}
	}
}


int main (int argc, char ** argv) {
	g_type_init ();
	return test_main (argc, argv);
}


test* test_new (void) {
	test* self;
	self = g_slice_new0 (test);
	return self;
}


void test_free (test* self) {
	g_slice_free (test, self);
}




_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to