if generateStructInfo gets invalid data, return null, do not throw: possibly duplicate struct names, and it is ok to return null

This commit is contained in:
Alon Zakai 2012-07-28 20:54:10 -07:00
Родитель 943f5a9c56
Коммит 8f1d44960c
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -280,7 +280,10 @@ var Runtime = {
offset = offset || 0;
type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
if (!type) return null;
assert(type.fields.length === struct.length, 'Number of named fields must match the type for ' + typeName);
if (type.fields.length != struct.length) {
printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
return null;
}
alignment = type.flatIndexes;
} else {
var type = { fields: struct.map(function(item) { return item[0] }) };

Просмотреть файл

@ -5143,6 +5143,19 @@ int main(int argc, char **argv) {
}
'''
self.do_run(src, 'value:10')
def test_fakestat(self):
src = r'''
#include <stdio.h>
struct stat { int x, y; };
int main() {
stat s;
s.x = 10;
s.y = 22;
printf("*%d,%d*\n", s.x, s.y);
}
'''
self.do_run(src, '*10,22*')
def test_mmap(self):
src = '''