aboutsummaryrefslogtreecommitdiff
path: root/db.c
diff options
context:
space:
mode:
Diffstat (limited to 'db.c')
-rw-r--r--db.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/db.c b/db.c
index bd2de17..c6ddab2 100644
--- a/db.c
+++ b/db.c
@@ -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;