* debugger/mcs51/break.c, debugger/mcs51/cmd.c,
[fw/sdcc] / as / link / lklibr.c
index 31d2e897aa472176a5facd25e961d6a9cac5204a..b56340a9b0ee51facf88811c2d3ea0caf2e64693 100644 (file)
@@ -22,6 +22,7 @@
 #define EQ(A,B) !strcmp((A),(B))
 #define MAXLINE 254 /*when using fgets*/
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -392,6 +393,7 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName)
 {
     char str[NINPUT+2];
     int state=0;
+    char *res;
 
     while (fgets(str, NINPUT, libfp) != NULL)
     {
@@ -402,7 +404,8 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName)
             case 0:
                 if(EQ(str, "<FILE>"))
                 {
-                    fgets(str, NINPUT, libfp);
+                    res = fgets(str, NINPUT, libfp);
+                    assert(res == str);
                     str[NINPUT+1] = '\0';
                     chop_crlf(str);
                     if(EQ(str, ModName)) state=1;
@@ -438,7 +441,9 @@ int LoadAdb(FILE * libfp)
 
     while (fgets(str, MAXLINE, libfp) != NULL)
     {
-        str[NINPUT+1] = '\0';
+        if (NINPUT < MAXLINE)
+            str[NINPUT+1] = '\0';
+
         chop_crlf(str);
         switch(state)
         {
@@ -467,11 +472,13 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
     char FLine[MAXLINE+1];
     int state=0;
     long IndexOffset=0, FileOffset;
+    char *res;
 
     while(!feof(libfp))
     {
         FLine[0]=0;
-        fgets(FLine, MAXLINE, libfp);
+        res = fgets(FLine, MAXLINE, libfp);
+        assert(res == FLine);
         chop_crlf(FLine);
 
         switch(state)
@@ -481,7 +488,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
                 {
                     /*The next line has the size of the index*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     IndexOffset=atol(FLine);
                     state=1;
@@ -493,7 +501,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
                     /*The next line has the name of the module and the offset
                     of the corresponding embedded file in the library*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     sscanf(FLine, "%s %ld", ModName, &FileOffset);
                     state=2;
@@ -738,8 +747,11 @@ int fndsym( char *name )
                     for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
                     for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
 #else
-                    realpath(FirstFound->libspc, absPath1);
-                    realpath(ThisLibr->libspc, absPath2);
+                    char *res;
+                    res = realpath(FirstFound->libspc, absPath1);
+                    assert(res == absPath1);
+                    res = realpath(ThisLibr->libspc, absPath2);
+                    assert(res == absPath2);
 #endif
                     if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
                     {
@@ -771,11 +783,13 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
     int state=0;
     long IndexOffset=0, FileOffset;
     pmlibrarysymbol ThisSym = NULL;
+    char *res;
 
     while(!feof(libfp))
     {
         FLine[0]=0;
-        fgets(FLine, MAXLINE, libfp);
+        res = fgets(FLine, MAXLINE, libfp);
+        assert(res == FLine);
         chop_crlf(FLine);
 
         switch(state)
@@ -785,7 +799,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
                 {
                     /*The next line has the size of the index*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     IndexOffset=atol(FLine);
                     state=1;
@@ -797,7 +812,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
                     /*The next line has the name of the module and the offset
                     of the corresponding embedded file in the library*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     sscanf(FLine, "%s %ld", ModName, &FileOffset);
                     state=2;