viewing paste Unknown #1625 | Plain text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/lighta/Documents/Myscript/RO/Servs/ra2/src
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: common/core.c
--- common/core.c Base (BASE)
+++ common/core.c Locally Modified (Based On LOCAL)
@@ -237,8 +237,8 @@
                        else
                        {
                                // Bin File format
-                               fgets(line, sizeof(line), fp); // Get the name
-                               fgets(line, sizeof(line), fp); // Get the entries kind
+                               if ( fgets(line, sizeof(line), fp) == NULL ) { printf("Can't get bin name\n"); } // Get the name
+                               if ( fgets(line, sizeof(line), fp) == NULL ) { printf("Can't get entries kind\n"); } // Get the entries kind
                                if(fgets(line, sizeof(line), fp)) // Get the rev numver
                                {
                                        snprintf(svn_version_buffer, sizeof(svn_version_buffer), "%d", atoi(line));
Index: common/grfio.c
--- common/grfio.c Base (BASE)
+++ common/grfio.c Locally Modified (Based On LOCAL)
@@ -403,7 +403,7 @@
                        declen = ftell(in);
                        fseek(in,0,SEEK_SET);
                        buf2 = (unsigned char *)aMalloc(declen+1);  // +1 for resnametable zero-termination
-                       (void)fread(buf2, 1, declen, in);
+                       if(fread(buf2, 1, declen, in) != declen) printf("An error occured in fread \n");
                        fclose(in);
 
                        if( size )
@@ -422,16 +422,17 @@
                char* grfname = gentry_table[entry->gentry - 1];
                FILE* in = fopen(grfname, "rb");
                if( in != NULL ) {
-                       unsigned char *buf = (unsigned char *)aMalloc(entry->srclen_aligned);
+                       int fsize = entry->srclen_aligned;
+                       unsigned char *buf = (unsigned char *)aMalloc(fsize);
                        fseek(in, entry->srcpos, 0);
-                       (void)fread(buf, 1, entry->srclen_aligned, in);
+                       if(fread(buf, 1, fsize, in) != fsize) printf("An error occured in fread \n");
                        fclose(in);
 
                        buf2 = (unsigned char *)aMalloc(entry->declen+1);  // +1 for resnametable zero-termination
                        if( entry->type & FILELIST_TYPE_FILE )
                        {// file
                                uLongf len;
-                               grf_decode(buf, entry->srclen_aligned, entry->type, entry->srclen);
+                               grf_decode(buf, fsize, entry->type, entry->srclen);
                                len = entry->declen;
                                decode_zip(buf2, &len, buf, entry->srclen);
                                if (len != (uLong)entry->declen) {
@@ -507,7 +508,7 @@
        grf_size = ftell(fp);
        fseek(fp,0,SEEK_SET);
 
-       (void)fread(grf_header,1,0x2e,fp);
+       if(fread(grf_header,1,0x2e,fp) != 0x2e) { ShowError("Couldn't read all grf_header element of %s \n", grfname); }
        if( strcmp((const char*)grf_header,"Master of Magic") != 0 || fseek(fp,getlong(grf_header+0x1e),SEEK_CUR) != 0 ) {
                fclose(fp);
                ShowError("GRF %s read error\n", grfname);
@@ -519,7 +520,7 @@
        if( grf_version == 0x01 ) {// ****** Grf version 01xx ******
                list_size = grf_size - ftell(fp);
                grf_filelist = (unsigned char *) aMalloc(list_size);
-               (void)fread(grf_filelist,1,list_size,fp);
+               if(fread(grf_filelist,1,list_size,fp) != list_size) { ShowError("Couldn't read all grf_filelist element of %s \n", grfname); }
                fclose(fp);
 
                entrys = getlong(grf_header+0x26) - getlong(grf_header+0x22) - 7;
@@ -566,7 +567,7 @@
                unsigned char *rBuf;
                uLongf rSize, eSize;
 
-               (void)fread(eheader,1,8,fp);
+               if(fread(eheader,1,8,fp) != 8) ShowError("An error occured in fread \n");
                rSize = getlong(eheader);       // Read Size
                eSize = getlong(eheader+4);     // Extend Size
 
@@ -578,7 +579,7 @@
 
                rBuf = (unsigned char *)aMalloc(rSize); // Get a Read Size
                grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size
-               (void)fread(rBuf,1,rSize,fp);
+               if(fread(rBuf,1,rSize,fp) != rSize) ShowError("An error occured in fread \n");
                fclose(fp);
                decode_zip(grf_filelist, &eSize, rBuf, rSize);  // Decode function
                aFree(rBuf);
Index: map/script.c
--- map/script.c Base (BASE)
+++ map/script.c Locally Modified (Based On LOCAL)
@@ -6125,9 +6125,8 @@
                return 0;
        }
        nbargs = script_lastdata(st)+1;
-       ShowInfo("nb args = %d\n",nbargs);
        if(nbargs%2){
-           ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n");  // returns string, regardless of what it was
+           ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n");
            script_pushint(st,0);
            return 1;
        }
@@ -6216,7 +6215,7 @@
 
         if( !data_isreference(data_it) || !data_isreference(data_nb))
         {
-                ShowError("script:checkweight3: parameter not a variable\n");
+                ShowError("script:checkweight2: parameter not a variable\n");
                 script_pushint(st,0);
                 return 1;// not a variable
         }
@@ -6229,12 +6228,12 @@
 
         if( not_array_variable(*name_it) || not_array_variable(*name_nb))
         {
-                ShowError("script:checkweight3: illegal scope\n");
+                ShowError("script:checkweight2: illegal scope\n");
                 script_pushint(st,0);
                 return 1;// not supported
         }
         if(is_string_variable(name_it) || is_string_variable(name_nb)){
-                ShowError("script:checkweight3: illegal type, need int\n");
+                ShowError("script:checkweight2: illegal type, need int\n");
                 script_pushint(st,0);
                 return 1;// not supported
         }
@@ -6254,12 +6253,12 @@
            if(fail) continue; //cpntonie to depop rest
 
             if(itemdb_exists(nameid) == NULL ){
-               ShowError("buildin_checkweight3: Invalid item '%d'.\n", nameid);
+               ShowError("buildin_checkweight2: Invalid item '%d'.\n", nameid);
                fail=1;
                continue;
             }
             if(amount < 0 ){
-                ShowError("buildin_checkweight3: Invalid amount '%d'.\n", amount);
+                ShowError("buildin_checkweight2: Invalid amount '%d'.\n", amount);
                 fail = 1;
                continue;
             }
Index: tool/mapcache.c
--- tool/mapcache.c Base (BASE)
+++ tool/mapcache.c Locally Modified (Based On LOCAL)
@@ -176,8 +176,8 @@
        encode_zip(write_buf, &len, m->cells, m->xs*m->ys);
 
        // Fill the map header
-       if (sizeof(name) > MAP_NAME_LENGTH) // It does not hurt to warn that there are maps with name longer than allowed.
-               ShowWarning ("Map name '%s' size '%d' is too long. Truncating to '%d'.\n", name, sizeof(name), MAP_NAME_LENGTH);
+       if (strlen(name) > MAP_NAME_LENGTH) // It does not hurt to warn that there are maps with name longer than allowed.
+               ShowWarning ("Map name '%s' size '%d' is too long. Truncating to '%d'.\n", name, strlen(name), MAP_NAME_LENGTH);
        strncpy(info.name, name, MAP_NAME_LENGTH);
        info.xs = MakeShortLE(m->xs);
        info.ys = MakeShortLE(m->ys);
@@ -201,12 +201,11 @@
 {
        int i;
        struct map_info info;
-       size_t fileReadCount;
       
        fseek(map_cache_fp, sizeof(struct main_header), SEEK_SET);
 
        for(i = 0; i < header.map_count; i++) {
-               fileReadCount = fread(&info, sizeof(info), 1, map_cache_fp);
+               if(fread(&info, sizeof(info), 1, map_cache_fp) != 1) printf("An error as occured in fread while reading map_cache\n");
                if(strcmp(name, info.name) == 0) // Map found
                        return 1;
                else // Map not found, jump to the beginning of the next map info header
@@ -305,8 +304,7 @@
                header.file_size = sizeof(struct main_header);
                header.map_count = 0;
        } else {
-               size_t fileReadCount;
-               fileReadCount = fread(&header, sizeof(struct main_header), 1, map_cache_fp);
+               if(fread(&header, sizeof(struct main_header), 1, map_cache_fp) != 1){ printf("An error as occured while reading map_cache_fp \n"); }
                header.file_size = GetULong((unsigned char *)&(header.file_size));
                header.map_count = GetUShort((unsigned char *)&(header.map_count));
        }
Viewed 340 times, submitted by unknown.