Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Ensure to skip empty list items (issue #20)
Browse files Browse the repository at this point in the history
We really need to drop glib sooner rather than later.
  • Loading branch information
Ikey Doherty committed Jan 12, 2016
1 parent 0b9c0b3 commit 459f411
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ static void cve_add_package_internal(struct source_package_t *pkg)
g_hash_table_insert(self->db, pkg->name, pkg);
}

static inline bool csv_string_empty(const char *p)
{
return (g_str_equal(p, "") || g_str_equal(p, ","));
}

/**
* Load CSV data, "faux" as this is metadata, not generated from scanned source
* files.
Expand Down Expand Up @@ -172,16 +177,16 @@ static bool load_faux(const char *path)
break;
}

strv[0] = g_strchomp(strv[0]);
strv[1] = g_strchomp(strv[1]);
strv[2] = g_strchomp(strv[2]);
strv[3] = g_strchomp(strv[3]);
strv[0] = g_strstrip(strv[0]);
strv[1] = g_strstrip(strv[1]);
strv[2] = g_strstrip(strv[2]);
strv[3] = g_strstrip(strv[3]);

if (streq(strv[0], "")) {
if (csv_string_empty(strv[0])) {
fprintf(stderr, "Line #%d: Package name cannot be empty\n", line);
break;
}
if (streq(strv[1], "")) {
if (csv_string_empty(strv[1])) {
fprintf(stderr, "Line #%d: Package version cannot be empty\n", line);
break;
}
Expand All @@ -203,10 +208,10 @@ static bool load_faux(const char *path)

t->name = g_strdup(strv[0]);
t->version = g_strdup(strv[1]);
if (!streq(strv[2], "")) {
if (!csv_string_empty(strv[2])) {
d->patched = g_strsplit(strv[2], " ", -1);
}
if (!streq(strv[3], "")) {
if (!csv_string_empty(strv[3])) {
d->ignored = g_strsplit(strv[3], " ", -1);
}
t->extra = d;
Expand Down

0 comments on commit 459f411

Please sign in to comment.