Mesa (master): os_stream: fix bugs in allocation path
Luca Barbieri
lb at kemper.freedesktop.org
Fri Aug 20 22:51:38 UTC 2010
Module: Mesa
Branch: master
Commit: 132b9439e287f1febbb49362671743a5b90e303c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=132b9439e287f1febbb49362671743a5b90e303c
Author: Luca Barbieri <luca at luca-barbieri.com>
Date: Sat Aug 21 00:39:48 2010 +0200
os_stream: fix bugs in allocation path
---
src/gallium/auxiliary/os/os_stream.c | 24 ++++++++----------------
1 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/gallium/auxiliary/os/os_stream.c b/src/gallium/auxiliary/os/os_stream.c
index 2d4e185..7b9c17c 100644
--- a/src/gallium/auxiliary/os/os_stream.c
+++ b/src/gallium/auxiliary/os/os_stream.c
@@ -9,28 +9,20 @@ os_default_stream_vprintf (struct os_stream* stream, const char *format, va_list
{
char buf[1024];
int retval;
-
- retval = util_vsnprintf(buf, sizeof(buf), format, ap);
+ va_list ap2;
+ va_copy(ap2, ap);
+ retval = util_vsnprintf(buf, sizeof(buf), format, ap2);
+ va_end(ap2);
if(retval <= 0)
{}
else if(retval < sizeof(buf))
stream->write(stream, buf, retval);
else
{
- int alloc = sizeof(buf);
- char* str = NULL;
- for(;;)
- {
- alloc += alloc;
- if(str)
- FREE(str);
- str = MALLOC(alloc);
- if(!str)
- return -1;
-
- retval = util_vsnprintf(str, alloc, format, ap);
- } while(retval >= alloc);
-
+ char* str = MALLOC(retval + 1);
+ if(!str)
+ return -1;
+ retval = util_vsnprintf(str, retval + 1, format, ap);
if(retval > 0)
stream->write(stream, str, retval);
FREE(str);
More information about the mesa-commit
mailing list