]> granicus.if.org Git - python/commitdiff
Avoid core dump in resizestring() on read() with 0 bytes.
authorGuido van Rossum <guido@python.org>
Tue, 11 Jun 1996 18:38:48 +0000 (18:38 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 11 Jun 1996 18:38:48 +0000 (18:38 +0000)
Modules/posixmodule.c

index 338a40c0d2504297de72b059f4e8a853a6492324..a4268dd9c50a235b9a43fb0c89ae9bf53b4774b8 100644 (file)
@@ -1408,7 +1408,7 @@ posix_read(self, args)
        object *self;
        object *args;
 {
-       int fd, size;
+       int fd, size, n;
        object *buffer;
        if (!getargs(args, "(ii)", &fd, &size))
                return NULL;
@@ -1416,13 +1416,14 @@ posix_read(self, args)
        if (buffer == NULL)
                return NULL;
        BGN_SAVE
-       size = read(fd, getstringvalue(buffer), size);
+       n = read(fd, getstringvalue(buffer), size);
        END_SAVE
-       if (size < 0) {
+       if (n < 0) {
                DECREF(buffer);
                return posix_error();
        }
-       resizestring(&buffer, size);
+       if (n != size)
+               resizestring(&buffer, n);
        return buffer;
 }