Skip to content

Commit

Permalink
Fix uninitialized variables in sdb
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Mar 12, 2014
1 parent b202b05 commit 35ece5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/fortunes
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,4 @@ I script in C, because fuck you
EXPLICIT CONTENT
bindings are mostly powered by tears
In Soviet Russia, Radare have documentation
Initial frame selected; you cannot go up.
11 changes: 8 additions & 3 deletions shlr/sdb/src/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ static SdbNs *sdb_ns_new (Sdb *s, const char *name, ut32 hash) {
memcpy (dir, s->dir, dir_len);
memcpy (dir+dir_len, ".", 1);
memcpy (dir+dir_len+1, name, name_len);
}
} else dir[0] = 0;
ns = malloc (sizeof (SdbNs));
if (!ns) return NULL;
ns->hash = hash;
ns->name = name? strdup (name): NULL;
ns->sdb = sdb_new (dir, name, 0);
ns->sdb = sdb_new (dir, ns->name, 0);
return ns;
}

Expand All @@ -55,6 +55,8 @@ SDB_API int sdb_ns_set (Sdb *s, const char *name, Sdb *r) {
ut32 hash = sdb_hashstr (name);
ls_foreach (s->ns, it, ns) {
if (ns->hash == hash) {
// implicit?
//sdb_free (ns->sdb);
ns->sdb = r;
return 1;
}
Expand All @@ -72,7 +74,10 @@ SDB_API int sdb_ns_set (Sdb *s, const char *name, Sdb *r) {
SDB_API Sdb *sdb_ns(Sdb *s, const char *name) {
SdbNs *ns;
SdbListIter *it;
ut32 hash = sdb_hashstr (name);
ut32 hash;
if (!name || !*name)
return NULL;
hash = sdb_hashstr (name);
ls_foreach (s->ns, it, ns) {
if (ns->hash == hash)
return ns->sdb;
Expand Down
2 changes: 2 additions & 0 deletions shlr/sdb/src/sdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SDB_API void sdb_global_hook(SdbHook hook, void *user) {
SDB_API Sdb* sdb_new (const char *path, const char *name, int lock) {
struct stat st = {0};
Sdb* s = R_NEW (Sdb);
if (!s) return NULL;
if (name && *name) {
if (path && *path) {
int plen = strlen (path);
Expand Down Expand Up @@ -58,6 +59,7 @@ SDB_API Sdb* sdb_new (const char *path, const char *name, int lock) {
s->fdump = -1;
s->ndump = NULL;
s->ns = ls_new (); // TODO: should be NULL
s->ns_lock = 0;
if (!s->ns) goto fail;
s->hooks = NULL;
s->ht = ht_new ((SdbListFree)sdb_kv_free);
Expand Down

0 comments on commit 35ece5c

Please sign in to comment.