strbuffer_value: Return a read-only pointer rather than duplicating the value
authorPetri Lehtinen <petri@digip.org>
Sat, 13 Jun 2009 19:26:45 +0000 (22:26 +0300)
committerPetri Lehtinen <petri@digip.org>
Sat, 13 Jun 2009 19:27:23 +0000 (22:27 +0300)
src/dump.c
src/strbuffer.c
src/strbuffer.h

index 83f3812..ce77b95 100644 (file)
@@ -222,7 +222,7 @@ char *json_dumps(const json_t *json, uint32_t flags)
     if(dump_to_strbuffer("\n", 1, (void *)&strbuff))
         return NULL;
 
-    result = strbuffer_value(&strbuff);
+    result = strdup(strbuffer_value(&strbuff));
     strbuffer_close(&strbuff);
 
     return result;
index 2445a75..911748d 100644 (file)
@@ -20,9 +20,9 @@ void strbuffer_close(strbuffer_t *strbuff)
     strbuffer_init(strbuff);
 }
 
-char *strbuffer_value(strbuffer_t *strbuff)
+const char *strbuffer_value(strbuffer_t *strbuff)
 {
-    return strdup(strbuff->value);
+    return strbuff->value;
 }
 
 char *strbuffer_steal_value(strbuffer_t *strbuff)
index 2b39135..c0e1cb8 100644 (file)
@@ -10,7 +10,7 @@ typedef struct {
 void strbuffer_init(strbuffer_t *strbuff);
 void strbuffer_close(strbuffer_t *strbuff);
 
-char *strbuffer_value(strbuffer_t *strbuff);
+const char *strbuffer_value(strbuffer_t *strbuff);
 char *strbuffer_steal_value(strbuffer_t *strbuff);
 
 int strbuffer_append(strbuffer_t *strbuff, const char *string);