diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-01-11 14:02:59 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-16 15:03:44 -0500 |
commit | 9c29369a04cdf47bd882579331577d82305bf785 (patch) | |
tree | 4a9752c89feb50c9fced1d18fdb4bbf24e3d9b72 /src/or/routerlist.c | |
parent | cc02823d7f6acbc3fa8ea87e5646921100796f10 (diff) | |
download | tor-9c29369a04cdf47bd882579331577d82305bf785.tar.gz tor-9c29369a04cdf47bd882579331577d82305bf785.zip |
Convert instances of tor_malloc+tor_snprintf into tor_asprintf
These were found by looking for tor_snprintf() instances that were
preceeded closely by tor_malloc(), though I probably converted some
more snprintfs as well.
(In every case, make sure that the length variable (if any) is
removed, renamed, or lowered, so that anything else that might have
assumed a longer buffer doesn't exist.)
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 689df99c57..b81289e856 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -2408,8 +2408,6 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed) int any_unwarned = 0; SMARTLIST_FOREACH_BEGIN(routerlist->routers, routerinfo_t *, router) { routerstatus_t *rs; - char *desc; - size_t dlen; char fp[HEX_DIGEST_LEN+1]; if (strcasecmp(router->nickname, nickname)) continue; @@ -2421,11 +2419,8 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed) } base16_encode(fp, sizeof(fp), router->cache_info.identity_digest, DIGEST_LEN); - dlen = 32 + HEX_DIGEST_LEN + strlen(router->address); - desc = tor_malloc(dlen); - tor_snprintf(desc, dlen, "\"$%s\" for the one at %s:%d", + smartlist_add_asprintf(fps, "\"$%s\" for the one at %s:%d", fp, router->address, router->or_port); - smartlist_add(fps, desc); } SMARTLIST_FOREACH_END(router); if (any_unwarned) { char *alternatives = smartlist_join_strings(fps, "; ",0,NULL); @@ -4071,7 +4066,6 @@ add_trusted_dir_server(const char *nickname, const char *address, trusted_dir_server_t *ent; uint32_t a; char *hostname = NULL; - size_t dlen; if (!trusted_dir_servers) trusted_dir_servers = smartlist_create(); @@ -4104,13 +4098,11 @@ add_trusted_dir_server(const char *nickname, const char *address, if (v3_auth_digest && (type & V3_DIRINFO)) memcpy(ent->v3_identity_digest, v3_auth_digest, DIGEST_LEN); - dlen = 64 + strlen(hostname) + (nickname?strlen(nickname):0); - ent->description = tor_malloc(dlen); if (nickname) - tor_snprintf(ent->description, dlen, "directory server \"%s\" at %s:%d", + tor_asprintf(&ent->description, "directory server \"%s\" at %s:%d", nickname, hostname, (int)dir_port); else - tor_snprintf(ent->description, dlen, "directory server at %s:%d", + tor_asprintf(&ent->description, "directory server at %s:%d", hostname, (int)dir_port); ent->fake_status.addr = ent->addr; @@ -5333,7 +5325,6 @@ esc_router_info(const routerinfo_t *router) { static char *info=NULL; char *esc_contact, *esc_platform; - size_t len; tor_free(info); if (!router) @@ -5342,10 +5333,7 @@ esc_router_info(const routerinfo_t *router) esc_contact = esc_for_log(router->contact_info); esc_platform = esc_for_log(router->platform); - len = strlen(esc_contact)+strlen(esc_platform)+32; - info = tor_malloc(len); - tor_snprintf(info, len, "Contact %s, Platform %s", esc_contact, - esc_platform); + tor_asprintf(&info, "Contact %s, Platform %s", esc_contact, esc_platform); tor_free(esc_contact); tor_free(esc_platform); |