DEADSOFTWARE

Исправлена порча памяти. На этот раз точно.
[dsw-obn.git] / src / oberon.c
index 0bbeec188b3d5b4e7fafe506285a9d096cb809b7..d6aefad6c94437641293674e57a730b7de2656e0 100644 (file)
@@ -356,23 +356,20 @@ oberon_init_scaner(oberon_context_t * ctx, const char * code)
 static void
 oberon_read_ident(oberon_context_t * ctx)
 {
-       int len = 0;
-       int i = ctx -> code_index;
+       int start = ctx -> code_index;
 
-       int c = ctx -> code[i];
-       while(isalnum(c))
+       oberon_get_char(ctx);
+       while(isalnum(ctx -> c))
        {
-               i += 1;
-               len += 1;
-               c = ctx -> code[i];
+               oberon_get_char(ctx);
        }
 
-       char * ident = GC_MALLOC(len + 1);
-       memcpy(ident, &ctx->code[ctx->code_index], len);
-       ident[len] = 0;
+       int end = ctx -> code_index;
+
+       char * ident = GC_MALLOC(end - start + 1);
+       memcpy(ident, &ctx -> code[start], end - start);
+       ident[end - start] = 0;
 
-       ctx -> code_index = i;
-       ctx -> c = ctx -> code[i];
        ctx -> string = ident;
        ctx -> token = IDENT;
 
@@ -738,7 +735,7 @@ static void oberon_read_string(oberon_context_t * ctx)
 
        char * string = GC_MALLOC(end - start + 1);
        strncpy(string, &ctx -> code[start], end - start);
-       string[end] = 0;
+       string[end - start] = 0;
 
        ctx -> token = STRING;
        ctx -> string = string;