mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-13 09:01:53 +03:00
Applied a bug fix on file reading code from John Ellson <ellson@lucent.com>, Daniel.
This commit is contained in:
12
parser.c
12
parser.c
@ -316,11 +316,11 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
|
||||
res = stat(filename, &buf);
|
||||
if (res < 0)
|
||||
return(NULL);
|
||||
len = buf.st_size+1;
|
||||
len = buf.st_size;
|
||||
if (len < MINLEN)
|
||||
len = MINLEN;
|
||||
}
|
||||
buffer = (char *)malloc(len*sizeof(char));
|
||||
buffer = (char *)malloc((len+1)*sizeof(char));
|
||||
if (buffer == NULL) {
|
||||
fprintf (stderr, "Cannot malloc\n");
|
||||
perror ("malloc failed");
|
||||
@ -335,7 +335,7 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
|
||||
#endif
|
||||
if (cnt >= len) {
|
||||
len *= 2;
|
||||
nbuf = (char *)realloc(buffer,len*sizeof(char));
|
||||
nbuf = (char *)realloc(buffer,(len+1)*sizeof(char));
|
||||
if (nbuf == NULL) {
|
||||
fprintf(stderr,"Cannot realloc\n");
|
||||
free(buffer);
|
||||
@ -4683,11 +4683,11 @@ xmlCreateFileParserCtxt(const char *filename)
|
||||
res = stat(filename, &buf);
|
||||
if (res < 0)
|
||||
return(NULL);
|
||||
len = buf.st_size+1;
|
||||
len = buf.st_size;
|
||||
if (len < MINLEN)
|
||||
len = MINLEN;
|
||||
}
|
||||
buffer = (char *)malloc(len*sizeof(char));
|
||||
buffer = (char *)malloc((len+1)*sizeof(char));
|
||||
if (buffer == NULL) {
|
||||
fprintf (stderr, "Cannot malloc\n");
|
||||
perror ("malloc failed");
|
||||
@ -4702,7 +4702,7 @@ xmlCreateFileParserCtxt(const char *filename)
|
||||
#endif
|
||||
if (cnt == len) {
|
||||
len *= 2;
|
||||
nbuf = (char *)realloc(buffer,len*sizeof(char));
|
||||
nbuf = (char *)realloc(buffer,(len+1)*sizeof(char));
|
||||
if (nbuf == NULL) {
|
||||
fprintf(stderr,"Cannot realloc\n");
|
||||
free(buffer);
|
||||
|
Reference in New Issue
Block a user