Преглед на файлове

Return nil in function_read_file if not found

As with `function_load`, this must return nil for the rest to work.
(Otherwise noone can detect if the file is not present or empty.)
Lucas Stadler преди 10 години
родител
ревизия
f4911b3598
променени са 1 файла, в които са добавени 8 реда и са изтрити 6 реда
  1. 8 6
      c/ton/main.c

+ 8 - 6
c/ton/main.c

@ -94,13 +94,15 @@ JSValueRef function_read_file(JSContextRef ctx, JSObjectRef function, JSObjectRe
94 94
		snprintf(full_path, 150, "%s/%s", "out", path);
95 95
96 96
		char *contents = get_contents(full_path);
97
		JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
98
		free(contents);
97
		if (contents != NULL) {
98
			JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
99
			free(contents);
99 100
100
		JSValueRef res[2];
101
		res[0] = JSValueMakeString(ctx, contents_str);
102
		res[1] = JSValueMakeNumber(ctx, 0);
103
		return JSObjectMakeArray(ctx, 2, res, NULL);
101
			JSValueRef res[2];
102
			res[0] = JSValueMakeString(ctx, contents_str);
103
			res[1] = JSValueMakeNumber(ctx, 0);
104
			return JSObjectMakeArray(ctx, 2, res, NULL);
105
		}
104 106
	}
105 107
106 108
	return JSValueMakeNull(ctx);