]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ftepp.c
fix: ftepp_delete needs to ftepp_flush to not cause a leak on errors
[xonotic/gmqcc.git] / ftepp.c
diff --git a/ftepp.c b/ftepp.c
index e1ee582c634c722eac2a285a575b595f9788bb15..b9a03690483ffc2633311ad20ca1bfbdca3411c2 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -77,13 +77,13 @@ typedef struct {
  * Implement the predef subsystem now.  We can do this safely with the
  * help of lexer contexts.
  */  
-static int ftepp_predef_countval = 0;
-static int ftepp_predef_randval  = 0;
+static uint32_t ftepp_predef_countval = 0;
+static uint32_t ftepp_predef_randval  = 0;
 
 /* __LINE__ */
 char *ftepp_predef_line(lex_file *context) {
-    char   *value = (char*)mem_a(128);
-    sprintf(value, "%d", (int)context->line);
+    char   *value;
+    util_asprintf(&value, "%d", (int)context->line);
     return value;
 }
 /* __FILE__ */
@@ -97,34 +97,34 @@ char *ftepp_predef_file(lex_file *context) {
 }
 /* __COUNTER_LAST__ */
 char *ftepp_predef_counterlast(lex_file *context) {
-    char   *value = (char*)mem_a(128);
-    sprintf(value, "%d", ftepp_predef_countval);
+    char   *value;
+    util_asprintf(&value, "%u", ftepp_predef_countval);
 
     (void)context;
     return value;
 }
 /* __COUNTER__ */
 char *ftepp_predef_counter(lex_file *context) {
-    char   *value = (char*)mem_a(128);
+    char   *value;
     ftepp_predef_countval ++;
-    sprintf(value, "%d", ftepp_predef_countval);
+    util_asprintf(&value, "%u", ftepp_predef_countval);
     (void)context;
 
     return value;
 }
 /* __RANDOM__ */
 char *ftepp_predef_random(lex_file *context) {
-    char  *value = (char*)mem_a(128);
-    ftepp_predef_randval = rand() % 0xFFFF; /* short int */
-    sprintf(value, "%d", ftepp_predef_randval);
+    char  *value;
+    ftepp_predef_randval = (util_rand() % 0xFF) + 1;
+    util_asprintf(&value, "%u", ftepp_predef_randval);
 
     (void)context;
     return value;
 }
 /* __RANDOM_LAST__ */
 char *ftepp_predef_randomlast(lex_file *context) {
-    char   *value = (char*)mem_a(128);
-    sprintf(value, "%d", ftepp_predef_randval);
+    char   *value;
+    util_asprintf(&value, "%u", ftepp_predef_randval);
 
     (void)context;
     return value;
@@ -234,6 +234,7 @@ static ftepp_t* ftepp_new()
 static void ftepp_delete(ftepp_t *self)
 {
     size_t i;
+    ftepp_flush(self);
     if (self->itemname)
         mem_d(self->itemname);
     if (self->includename)