diff options
author | John Ankarström <john@ankarstrom.se> | 2021-09-17 22:34:52 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-09-17 22:34:52 +0200 |
commit | 56509ab16c8d2225182eb0400e5c6a4900870391 (patch) | |
tree | e3c3bcc760ecc187a3f4ee8c6616855d15e86d83 /db.c | |
parent | 3e400c3df5572524b7ba08b030f45eb3ba6b7734 (diff) | |
download | cforum-56509ab16c8d2225182eb0400e5c6a4900870391.tar.gz |
Fix mktpl bug
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -21,6 +21,12 @@ byid(int id, char *sql) return stmt; } +char * +textdup(const unsigned char *s) +{ + return s? strdup((char *)s): NULL; +} + struct post * getpost(int id) { @@ -39,8 +45,8 @@ getpost(int id) post->user = sqlite3_column_int(stmt, 1); post->created = sqlite3_column_int(stmt, 2); post->edited = sqlite3_column_int(stmt, 3); - post->subject = strdup((char *)sqlite3_column_text(stmt, 4)); - post->text = strdup((char *)sqlite3_column_text(stmt, 5)); + post->subject = textdup(sqlite3_column_text(stmt, 4)); + post->text = textdup(sqlite3_column_text(stmt, 5)); sqlite3_finalize(stmt); return post; @@ -61,9 +67,9 @@ getuser(int id) err(1, "malloc"); user->id = id; - user->name = strdup((char *)sqlite3_column_text(stmt, 0)); - user->full = strdup((char *)sqlite3_column_text(stmt, 1)); - user->hash = strdup((char *)sqlite3_column_text(stmt, 2)); + user->name = textdup(sqlite3_column_text(stmt, 0)); + user->full = textdup(sqlite3_column_text(stmt, 1)); + user->hash = textdup(sqlite3_column_text(stmt, 2)); sqlite3_finalize(stmt); return user; |