summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2010-07-09 19:56:58 -0700
committerJoshua Haberman <joshua@reverberate.org>2010-07-09 19:56:58 -0700
commitb04ff41664f45c3c86eea62173a1223ff04d6ad7 (patch)
tree25e4c47ddcb8cb90c34b397ab1059f730e151100 /src
parentbe5ddd8a645eaa949a8d500718257fb7cb71cf44 (diff)
Dynamically allocate string for error msg.
Diffstat (limited to 'src')
-rw-r--r--src/upb.c12
-rw-r--r--src/upb.h12
2 files changed, 14 insertions, 10 deletions
diff --git a/src/upb.c b/src/upb.c
index 3c5efe8..a98512d 100644
--- a/src/upb.c
+++ b/src/upb.c
@@ -10,6 +10,7 @@
#include <string.h>
#include "upb.h"
+#include "upb_string.h"
#define alignof(t) offsetof(struct { char c; t x; }, x)
#define TYPE_INFO(wire_type, ctype, allows_delimited) \
@@ -43,10 +44,12 @@ void upb_seterr(upb_status *status, enum upb_status_code code,
const char *msg, ...)
{
if(upb_ok(status)) { // The first error is the most interesting.
+ status->str = upb_string_new();
+ char *str = upb_string_getrwbuf(status->str, UPB_ERRORMSG_MAXLEN);
status->code = code;
va_list args;
va_start(args, msg);
- vsnprintf(status->msg, UPB_ERRORMSG_MAXLEN, msg, args);
+ vsnprintf(str, UPB_ERRORMSG_MAXLEN, msg, args);
va_end(args);
}
}
@@ -54,6 +57,11 @@ void upb_seterr(upb_status *status, enum upb_status_code code,
void upb_copyerr(upb_status *to, upb_status *from)
{
to->code = from->code;
- strcpy(to->msg, from->msg);
+ to->str = upb_string_getref(from->str);
}
+void upb_reset(upb_status *status) {
+ status->code = UPB_STATUS_OK;
+ upb_string_unref(status->str);
+ status->str = NULL;
+}
diff --git a/src/upb.h b/src/upb.h
index 6bf548c..6502dfc 100644
--- a/src/upb.h
+++ b/src/upb.h
@@ -281,23 +281,19 @@ enum upb_status_code {
UPB_ERROR_MAX_NESTING_EXCEEDED = -3
};
-#define UPB_ERRORMSG_MAXLEN 256
typedef struct {
enum upb_status_code code;
- char msg[UPB_ERRORMSG_MAXLEN];
+ upb_string *str;
} upb_status;
-#define UPB_STATUS_INIT {UPB_STATUS_OK, ""}
+#define UPB_STATUS_INIT {UPB_STATUS_OK, NULL}
+#define UPB_ERRORMSG_MAXLEN 256
INLINE bool upb_ok(upb_status *status) {
return status->code == UPB_STATUS_OK;
}
-INLINE void upb_reset(upb_status *status) {
- status->code = UPB_STATUS_OK;
- status->msg[0] = '\0';
-}
-
+void upb_reset(upb_status *status);
void upb_seterr(upb_status *status, enum upb_status_code code, const char *msg,
...);
void upb_copyerr(upb_status *to, upb_status *from);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback