Changeset 1251


Ignore:
Timestamp:
01/16/10 14:49:56 (11 years ago)
Author:
Admin
Message:

WebIf: Fix reading large templates from config dir.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/monitor-improvement/oscam-http-helpers.c

    r1233 r1251  
    161161            FILE *fp;
    162162            char buffer[1024];
    163             int read, allocated = 1025, size = 1;
     163            int read, allocated = 1025, size = 0;
    164164            result = (char *) malloc(allocated * sizeof(char));
    165165            if((fp = fopen(path,"r"))!=NULL){
    166166            while((read = fread(&buffer,sizeof(char),1024,fp)) > 0){
    167                 size += read;
    168                 if(allocated < size) {
     167                if(allocated < size + read + 1) {
    169168                    allocated += size + 1024;
    170169                    result = (char *) realloc(result, allocated * sizeof(char));
    171170                }
    172                 memcpy(result, buffer, read);
     171                memcpy(result + size, buffer, read);
     172                size += read;
    173173            }
    174             result[size - 1] = '\0';
     174            result[size] = '\0';
    175175            fclose (fp);
    176176            return result;
Note: See TracChangeset for help on using the changeset viewer.