]> granicus.if.org Git - python/commitdiff
Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 26 May 2008 22:07:28 +0000 (22:07 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 26 May 2008 22:07:28 +0000 (22:07 +0000)
passed in.  (The assert won't prevent this in non-debug builds).

Python/mysnprintf.c

index 8c477946427d1cd70d9e4b59edfffe53761fcc54..3173863c466f6aa16b3e1f682ee46de63f152c47 100644 (file)
@@ -98,7 +98,8 @@ PyOS_vsnprintf(char *str, size_t size, const char  *format, va_list va)
        PyMem_FREE(buffer);
 #endif
 Done:
-       str[size-1] = '\0';
+       if (size > 0)
+               str[size-1] = '\0';
        return len;
 #undef _PyOS_vsnprintf_EXTRA_SPACE
 }