Don't have side effects in assert

master
Drew DeVault 6 years ago
parent 55056947a7
commit cfbf2130da
  1. 11
      src/main.c

@ -16,7 +16,8 @@ static int parse_section(struct parser *p) {
uint32_t ch; uint32_t ch;
while ((ch = parser_getch(p)) != UTF8_INVALID) { while ((ch = parser_getch(p)) != UTF8_INVALID) {
if (ch < 0x80 && isdigit(ch)) { if (ch < 0x80 && isdigit(ch)) {
assert(str_append_ch(section, ch) != -1); int ret = str_append_ch(section, ch);
assert(ret != -1);
} else if (ch == ')') { } else if (ch == ')') {
if (!section->str) { if (!section->str) {
break; break;
@ -72,7 +73,8 @@ static void parse_preamble(struct parser *p) {
strftime(date, sizeof(date), "%F", now_tm); strftime(date, sizeof(date), "%F", now_tm);
while ((ch = parser_getch(p)) != UTF8_INVALID) { while ((ch = parser_getch(p)) != UTF8_INVALID) {
if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') { if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') {
assert(str_append_ch(name, ch) != -1); int ret = str_append_ch(name, ch);
assert(ret != -1);
} else if (ch == '(') { } else if (ch == '(') {
section = parse_section(p); section = parse_section(p);
} else if (ch == '"') { } else if (ch == '"') {
@ -482,8 +484,9 @@ static void parse_table(struct parser *p, uint32_t style) {
switch (ch) { switch (ch) {
case '\n': case '\n':
goto commit_cell; goto commit_cell;
default: default:;
assert(str_append_ch(curcell->contents, ch) != -1); int ret = str_append_ch(curcell->contents, ch);
assert(ret != -1);
break; break;
} }
} }

Loading…
Cancel
Save