Fix macro reusing variable names leading to string corruption.
This commit is contained in:
parent
709c307145
commit
199243af79
@ -1109,8 +1109,8 @@ static bool _json_get_string(char **store, const json_t *entry, const char *res)
|
||||
goto out;
|
||||
}
|
||||
buf = json_string_value(entry);
|
||||
LOGDEBUG("Json found entry %s: %s", res, buf);
|
||||
*store = strdup(buf);
|
||||
LOGDEBUG("Json found entry %s: %s", res, *store);
|
||||
ret = true;
|
||||
out:
|
||||
return ret;
|
||||
|
||||
@ -198,20 +198,20 @@ void logmsg(int loglevel, const char *fmt, ...);
|
||||
#define DEFLOGBUFSIZ 512
|
||||
|
||||
#define LOGMSGSIZ(__siz, __lvl, __fmt, ...) do { \
|
||||
char *buf; \
|
||||
int len, offset = 0; \
|
||||
ASPRINTF(&buf, __fmt, ##__VA_ARGS__); \
|
||||
len = strlen(buf); \
|
||||
while (len > 0) { \
|
||||
char tmp42[__siz] = {}; \
|
||||
int cpy = MIN(len, DEFLOGBUFSIZ - 2); \
|
||||
memcpy(tmp42, buf + offset, cpy); \
|
||||
logmsg(__lvl, "%s", tmp42);\
|
||||
offset += cpy; \
|
||||
len -= offset; \
|
||||
} \
|
||||
free(buf); \
|
||||
} while(0)
|
||||
char *BUF; \
|
||||
int LEN, OFFSET = 0; \
|
||||
ASPRINTF(&BUF, __fmt, ##__VA_ARGS__); \
|
||||
LEN = strlen(BUF); \
|
||||
while (LEN > 0) { \
|
||||
char tmp42[__siz] = {}; \
|
||||
int CPY = MIN(LEN, DEFLOGBUFSIZ - 2); \
|
||||
memcpy(tmp42, BUF + OFFSET, CPY); \
|
||||
logmsg(__lvl, "%s", tmp42);\
|
||||
OFFSET += CPY; \
|
||||
LEN -= OFFSET; \
|
||||
} \
|
||||
free(BUF); \
|
||||
} while(0)
|
||||
|
||||
#define LOGMSG(_lvl, _fmt, ...) \
|
||||
LOGMSGSIZ(DEFLOGBUFSIZ, _lvl, _fmt, ##__VA_ARGS__)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user