diff options
-rw-r--r-- | src/fragment.c | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/src/fragment.c b/src/fragment.c index 2b11df34..a1c9e6e4 100644 --- a/src/fragment.c +++ b/src/fragment.c @@ -34,8 +34,6 @@ #define COMP_FUNCTION_ARB_MASK (1 << 0) #define COMP_FUNCTION_MASK (COMP_FUNCTION_ARB_MASK) -#define BUFFER_SIZE 1024 - struct _CompProgram { struct _CompProgram *next; @@ -1037,7 +1035,7 @@ addDataOpToFunctionData (CompFunctionData *data, ...) { int index = data->nBody; - int size = BUFFER_SIZE; + int size = strlen (str) + 1; int n; char *fStr; char *tmp; @@ -1046,39 +1044,41 @@ addDataOpToFunctionData (CompFunctionData *data, if (!allocBodyOpInFunctionData (data)) return FALSE; - if ((fStr = malloc (size)) == NULL) + fStr = malloc (size); + if (!fStr) return FALSE; while (1) { /* Try to print in the allocated space. */ - va_start(ap, str); + va_start (ap, str); n = vsnprintf (fStr, size, str, ap); - va_end(ap); - + va_end (ap); + /* If that worked, leave the loop. */ if (n > -1 && n < size) break; - + /* Else try again with more space. */ - if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ - - if ((tmp = realloc (fStr, size)) == NULL) + if (n > -1) /* glibc 2.1 */ + size = n + 1; /* precisely what is needed */ + else /* glibc 2.0 */ + size++; /* one more than the old size */ + + tmp = realloc (fStr, size); + if (!tmp) { - free(fStr); + free (fStr); return FALSE; - } else { + } + else + { fStr = tmp; } } data->body[index].type = CompOpTypeData; - data->body[index].data.data = strdup (fStr); - - free (fStr); + data->body[index].data.data = fStr; return TRUE; } @@ -1089,7 +1089,7 @@ addBlendOpToFunctionData (CompFunctionData *data, ...) { int index = data->nBody; - int size = BUFFER_SIZE; + int size = strlen (str) + 1; int n; char *fStr; char *tmp; @@ -1098,39 +1098,41 @@ addBlendOpToFunctionData (CompFunctionData *data, if (!allocBodyOpInFunctionData (data)) return FALSE; - if ((fStr = malloc (size)) == NULL) + fStr = malloc (size); + if (!fStr) return FALSE; while (1) { /* Try to print in the allocated space. */ - va_start(ap, str); + va_start (ap, str); n = vsnprintf (fStr, size, str, ap); - va_end(ap); - + va_end (ap); + /* If that worked, leave the loop. */ if (n > -1 && n < size) break; - + /* Else try again with more space. */ - if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ - - if ((tmp = realloc (fStr, size)) == NULL) + if (n > -1) /* glibc 2.1 */ + size = n + 1; /* precisely what is needed */ + else /* glibc 2.0 */ + size++; /* one more than the old size */ + + tmp = realloc (fStr, size); + if (!tmp) { - free(fStr); + free (fStr); return FALSE; - } else { + } + else + { fStr = tmp; } } data->body[index].type = CompOpTypeDataBlend; - data->body[index].data.data = strdup (fStr); - - free (fStr); + data->body[index].data.data = fStr; return TRUE; } |