Commit 1e755594 1e75559474e8d8a062a4f869f6421e6dee181cd3 by Sergey Poznyakoff

(internal_icvt_read,copy_octal): Fixed memory allocation errors.

1 parent fc577d5c
...@@ -204,6 +204,7 @@ internal_icvt_read (stream_t stream, char *optr, size_t osize, size_t *pnbytes) ...@@ -204,6 +204,7 @@ internal_icvt_read (stream_t stream, char *optr, size_t osize, size_t *pnbytes)
204 char *p = realloc (s->buf, s->bufsize + 128); 204 char *p = realloc (s->buf, s->bufsize + 128);
205 if (!p) 205 if (!p)
206 return ENOMEM; 206 return ENOMEM;
207 s->buf = p;
207 s->bufsize += 128; 208 s->bufsize += 128;
208 } 209 }
209 continue; 210 continue;
...@@ -255,7 +256,10 @@ copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes) ...@@ -255,7 +256,10 @@ copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
255 /* Try to reallocate temp buffer */ 256 /* Try to reallocate temp buffer */
256 char *p = realloc (s->buf, rdcount); 257 char *p = realloc (s->buf, rdcount);
257 if (p) 258 if (p)
258 s->bufsize = rdcount; 259 {
260 s->bufsize = rdcount;
261 s->buf = p;
262 }
259 else 263 else
260 rdcount = s->bufsize; 264 rdcount = s->bufsize;
261 } 265 }
...@@ -279,7 +283,7 @@ copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes) ...@@ -279,7 +283,7 @@ copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
279 { 283 {
280 if (ISPRINT (*(unsigned char*)(s->buf+i))) 284 if (ISPRINT (*(unsigned char*)(s->buf+i)))
281 optr[j++] = s->buf[i]; 285 optr[j++] = s->buf[i];
282 else if (j + 4 >= s->bufpos) 286 else if (j + 4 >= osize)
283 break; 287 break;
284 else 288 else
285 { 289 {
......