changeset 221:271c0ef9ea60

Fixed segfault in import/extern pseudo op
author lost
date Sat, 09 May 2009 16:32:47 +0000
parents 2b254f02b252
children 7803d2d09993
files ChangeLog lwasm/pseudo.c
diffstat 2 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat May 09 16:21:54 2009 +0000
+++ b/ChangeLog	Sat May 09 16:32:47 2009 +0000
@@ -14,7 +14,9 @@
 Version 2.4
 
 [!] Fixed off by one relocation offest for base page external references
-    generated by lwasm
+    generated by lwasm [LWASM]
+[b] Fixed segfault in "extern" pseudo op and allowed a symbol list as the
+    operand just like "export" [LWASM]
 
 Version 2.3
 
--- a/lwasm/pseudo.c	Sat May 09 16:21:54 2009 +0000
+++ b/lwasm/pseudo.c	Sat May 09 16:32:47 2009 +0000
@@ -1031,7 +1031,38 @@
 		return;
 	}
 	
-	lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
+	if (l -> sym)
+	{
+		lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
+		return;
+	}
+	
+	while (**p)
+	{
+		char *sym2, *sym3;
+		for (sym2 = *p; **p && !isspace(**p) && **p != ','; (*p)++)
+			/* do nothing */ ;
+
+		if (l -> sym)
+			lwasm_free(l -> sym);
+
+		sym3 = lwasm_alloc(*p - sym2 + 1);
+		memcpy(sym3, sym2, *p - sym2);
+		sym3[*p - sym2] = '\0';
+			
+		l -> sym = sym3;
+		debug_message(2, "import symbol: '%s'", sym3);
+		lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
+		if (**p && (**p != ','))
+		{
+			register_error(as, l, 1, "Bad import list");
+			return;
+		}
+		if (**p == ',')
+			(*p)++;
+	}
+	if (!(l -> sym))
+		register_error(as, l, 1, "Bad import list");
 }
 
 OPFUNC(pseudo_export)