From 8c697312e424055100eb937f40f57f136bb644aa Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Sat, 13 Jun 2009 22:26:45 +0300 Subject: [PATCH] strbuffer_value: Return a read-only pointer rather than duplicating the value --- src/dump.c | 2 +- src/strbuffer.c | 4 ++-- src/strbuffer.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dump.c b/src/dump.c index 83f3812..ce77b95 100644 --- a/src/dump.c +++ b/src/dump.c @@ -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; diff --git a/src/strbuffer.c b/src/strbuffer.c index 2445a75..911748d 100644 --- a/src/strbuffer.c +++ b/src/strbuffer.c @@ -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) diff --git a/src/strbuffer.h b/src/strbuffer.h index 2b39135..c0e1cb8 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -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); -- 2.7.4