* doc/sdccman.lyx,
[fw/sdcc] / src / SDCCval.c
index 88fa5470d8b09f3bc3a55ec53689e2e76f7d2f7e..649388f7f6e0c442cf0d15949e880495fe81a883 100644 (file)
@@ -53,12 +53,11 @@ newiList (int type, void *ilist)
 {
   initList *nilist;
 
-
   nilist = Safe_alloc (sizeof (initList));
 
   nilist->type = type;
-  nilist->lineno = lexLineno;
   nilist->filename = lexFilename;
+  nilist->lineno = lexLineno;
 
   switch (type)
     {
@@ -75,7 +74,7 @@ newiList (int type, void *ilist)
 }
 
 /*------------------------------------------------------------------*/
-/* revinit   - reverses the initial values for a value  chain        */
+/* revinit   - reverses the initial values for a value chain        */
 /*------------------------------------------------------------------*/
 initList *
 revinit (initList * val)
@@ -100,19 +99,20 @@ revinit (initList * val)
 }
 
 bool
-convertIListToConstList(initList *src, literalList **lList)
+convertIListToConstList(initList *src, literalList **lList, int size)
 {
+    int cnt = 0;
     initList    *iLoop;
     literalList *head, *last, *newL;
 
     head = last = NULL;
 
-    if (!src || src->type != INIT_DEEP)
+    if (src && src->type != INIT_DEEP)
     {
         return FALSE;
     }
 
-    iLoop =  src->init.deep;
+    iLoop = src ? src->init.deep : NULL;
 
     while (iLoop)
     {
@@ -126,14 +126,19 @@ convertIListToConstList(initList *src, literalList **lList)
             return FALSE;
         }
         iLoop = iLoop->next;
+        cnt++;
+    }
+    if (!size)
+    {
+        size = cnt;
     }
 
     /* We've now established that the initializer list contains only literal values. */
 
-    iLoop = src->init.deep;
-    while (iLoop)
+    iLoop = src ? src->init.deep : NULL;
+    while (size--)
     {
-        double val = AST_FLOAT_VALUE(iLoop->init.node);
+        double val = iLoop ? AST_FLOAT_VALUE(iLoop->init.node) : 0;
 
         if (last && last->literalValue == val)
         {
@@ -156,7 +161,7 @@ convertIListToConstList(initList *src, literalList **lList)
             }
             last = newL;
         }
-        iLoop = iLoop->next;
+        iLoop = iLoop ? iLoop->next : NULL;
     }
 
     if (!head)
@@ -201,7 +206,7 @@ copyLiteralList(literalList *src)
 
 
 /*------------------------------------------------------------------*/
-/* copyIlist - copy initializer list            */
+/* copyIlist - copy initializer list                                */
 /*------------------------------------------------------------------*/
 initList *
 copyIlist (initList * src)
@@ -262,6 +267,8 @@ list2val (initList * val)
 ast *
 list2expr (initList * ilist)
 {
+  if (!ilist)
+    return NULL;
   if (ilist->type == INIT_DEEP)
     return list2expr (ilist->init.deep);
   return ilist->init.node;
@@ -1368,8 +1375,7 @@ valDiv (value * lval, value * rval)
 
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) / floatFromVal (rval);
-  else
-  if (IS_FIXED16X16 (val->type))
+  else if (IS_FIXED16X16 (val->type))
     SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble( floatFromVal (lval) / floatFromVal (rval) );
   else if (SPEC_LONG (val->type))
     {