raa_read() is defined to return 0 for all uninitialized entries, do
authorH. Peter Anvin <hpa@zytor.com>
Sun, 26 May 2002 22:30:48 +0000 (22:30 +0000)
committerH. Peter Anvin <hpa@zytor.com>
Sun, 26 May 2002 22:30:48 +0000 (22:30 +0000)
not issue an error.

Some minor ANSI C cleanups (memset(...,0,...) is *not* a valid way to
initialize an array of pointers to NULL.)

nasmlib.c

index c362c20..003e14e 100644 (file)
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -330,16 +330,18 @@ void standard_extension (char *inname, char *outname, char *extension,
 static struct RAA *real_raa_init (int layers) 
 {
     struct RAA *r;
+    int i;
+
+    r->layers = layers;
 
     if (layers == 0) {
        r = nasm_malloc (LEAFSIZ);
        memset (r->u.l.data, 0, sizeof(r->u.l.data));
-       r->layers = 0;
        r->stepsize = 1L;
     } else {
        r = nasm_malloc (BRANCHSIZ);
-       memset (r->u.b.data, 0, sizeof(r->u.b.data));
-       r->layers = layers;
+       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
+         r->u.b.data[i] = NULL;
        r->stepsize = RAA_BLKSIZE;
        while (--layers)
            r->stepsize *= RAA_LAYERSIZE;
@@ -367,14 +369,14 @@ void raa_free (struct RAA *r)
 long raa_read (struct RAA *r, long posn) 
 {
     if (posn > r->stepsize * LAYERSIZ(r))
-        nasm_malloc_error (ERR_PANIC, "bad position in raa_read");
+       return 0;               /* Return 0 for undefined entries */
     while (r->layers > 0) {
        ldiv_t l;
        l = ldiv (posn, r->stepsize);
        r = r->u.b.data[l.quot];
        posn = l.rem;
-       if (!r)                        /* better check this */
-            nasm_malloc_error (ERR_PANIC, "null pointer in raa_read");
+       if (!r)
+           return 0;           /* Return 0 for undefined entries */
     }
     return r->u.l.data[posn];
 }
@@ -388,12 +390,14 @@ struct RAA *raa_write (struct RAA *r, long posn, long value)
 
     while (r->stepsize * LAYERSIZ(r) < posn) {
        /*
-        * Must go up a layer.
+        * Must add a layer.
         */
        struct RAA *s;
+       int i;
 
        s = nasm_malloc (BRANCHSIZ);
-       memset (s->u.b.data, 0, sizeof(r->u.b.data));
+       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
+           s->u.b.data[i] = NULL;
        s->layers = r->layers + 1;
        s->stepsize = LAYERSIZ(r) * r->stepsize;
        s->u.b.data[0] = r;