chore: more lint fixes

This commit is contained in:
Krzysztof Rudnicki 2025-09-08 16:10:08 +02:00
parent fde196337e
commit 37206cb3fd

View File

@ -123,30 +123,11 @@ static size_t json_escaped_len(const char* s) {
} }
static inline char* json_append_escaped(char* w, char c) { static inline char* json_append_escaped(char* w, char c) {
switch (c) { if (c == '"' || c == '\\') { *w++ = '\\'; *w++ = c; return w; }
case '"': if (c == '\n') { *w++ = '\\'; *w++ = 'n'; return w; }
*w++ = '\\'; if (c == '\r') { *w++ = '\\'; *w++ = 'r'; return w; }
*w++ = '"'; if (c == '\t') { *w++ = '\\'; *w++ = 't'; return w; }
break; *w++ = c; return w;
case '\\':
*w++ = '\\';
*w++ = '\\';
break;
case '\n':
*w++ = '\\';
*w++ = 'n';
break;
case '\r':
*w++ = '\\';
*w++ = 'r';
break;
case '\t':
*w++ = '\\';
*w++ = 't';
break;
default: *w++ = c; break;
}
return w;
} }
static void json_escape_into(char* out, const char* s) { static void json_escape_into(char* out, const char* s) {
@ -183,23 +164,12 @@ static inline char json_unescape_char(char c) {
} }
static void parse_json_string_core(const char* v, char* out, size_t* w, const char** after_end) { static void parse_json_string_core(const char* v, char* out, size_t* w, const char** after_end) {
bool esc = false; bool esc = false; const char* p = v;
const char* p = v;
for (; *p; ++p) { for (; *p; ++p) {
char c = *p; char c = *p;
if (esc) { if (esc) { out[(*w)++] = json_unescape_char(c); esc = false; continue; }
out[(*w)++] = json_unescape_char(c); if (c == '\\') { esc = true; continue; }
esc = false; if (c == '"') { *after_end = p + 1; break; }
continue;
}
if (c == '\\') {
esc = true;
continue;
}
if (c == '"') {
*after_end = p + 1;
break;
}
out[(*w)++] = c; out[(*w)++] = c;
} }
if (!*after_end) *after_end = p; if (!*after_end) *after_end = p;
@ -979,7 +949,17 @@ static char* create_article_from_body(const char* body_json) {
size_t i = 1, len = strlen(tcontent); size_t i = 1, len = strlen(tcontent);
char** items = NULL; char** items = NULL;
size_t cap = 0, cnt = 0; size_t cap = 0, cnt = 0;
push_str(&items, &cap, &cnt, strdup(obj)); {
char* dup = strdup(obj);
if (!dup || push_str(&items, &cap, &cnt, dup)) {
free(dup);
free(tcontent);
free(file);
free(id);
free(obj);
return NULL;
}
}
while (1) { while (1) {
char* one = NULL; char* one = NULL;
int r = find_next_json_object(tcontent, len, &i, &one); int r = find_next_json_object(tcontent, len, &i, &one);
@ -1272,7 +1252,7 @@ typedef struct {
long long createdAt; long long createdAt;
} ArticleFields; } ArticleFields;
static void load_fields(char* obj, ArticleFields* f) { static void load_fields(const char* obj, ArticleFields* f) {
f->title = json_get_string(obj, "title"); f->title = json_get_string(obj, "title");
f->author = json_get_string(obj, "author"); f->author = json_get_string(obj, "author");
f->body = json_get_string(obj, "body"); f->body = json_get_string(obj, "body");