Quellcode durchsuchen

Return nil in function_load if file is not present

The other file-opening functions might have similar behaviour, and still
need to be checked.
Lucas Stadler vor 9 Jahren
Ursprung
Commit
5cb9cba628
1 geänderte Dateien mit 9 neuen und 3 gelöschten Zeilen
  1. 9 3
      c/ton/main.c

+ 9 - 3
c/ton/main.c

@ -117,12 +117,18 @@ JSValueRef function_load(JSContextRef ctx, JSObjectRef function, JSObjectRef thi
117 117
		// TODO: should not load from here?
118 118
		snprintf(full_path, 150, "%s/%s", "out", path);
119 119
120
		JSValueRef contents_val = NULL;
121
120 122
		char *contents = get_contents(full_path);
121
		JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
122
		free(contents);
123
		if (contents != NULL) {
124
			JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
125
			free(contents);
126
127
			contents_val = JSValueMakeString(ctx, contents_str);
128
		}
123 129
124 130
		JSValueRef res[2];
125
		res[0] = JSValueMakeString(ctx, contents_str);
131
		res[0] = contents_val;
126 132
		res[1] = JSValueMakeNumber(ctx, 0);
127 133
		return JSObjectMakeArray(ctx, 2, res, NULL);
128 134
	}