summaryrefslogtreecommitdiffstats
path: root/support/htdbm.c
diff options
context:
space:
mode:
authorDaniel Earl Poirier <poirier@apache.org>2009-09-14 21:08:22 +0200
committerDaniel Earl Poirier <poirier@apache.org>2009-09-14 21:08:22 +0200
commit2006220dec7884aef21f341ebfd58ab7f6070ebb (patch)
tree0cdedca9a45d0080f32eb44d14957040538f07a2 /support/htdbm.c
parentMove declaration to remove a compiler warning. (diff)
downloadapache2-2006220dec7884aef21f341ebfd58ab7f6070ebb.tar.xz
apache2-2006220dec7884aef21f341ebfd58ab7f6070ebb.zip
htdbm: don't allocate more memory for every record we dump.
Thanks to Jeff Trawick for flagging this. Also ensure a space before all dumped comments. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@814781 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support/htdbm.c')
-rw-r--r--support/htdbm.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/support/htdbm.c b/support/htdbm.c
index 74bff82003..8baa75ebb6 100644
--- a/support/htdbm.c
+++ b/support/htdbm.c
@@ -241,8 +241,7 @@ static apr_status_t htdbm_list(htdbm_t *htdbm)
{
apr_status_t rv;
apr_datum_t key, val;
- char *rec, *cmnt;
- char *kb;
+ char *cmnt;
int i = 0;
rv = apr_dbm_firstkey(htdbm->dbm, &key);
@@ -251,19 +250,18 @@ static apr_status_t htdbm_list(htdbm_t *htdbm)
return APR_ENOENT;
}
fprintf(stderr, "Dumping records from database -- %s\n", htdbm->filename);
- fprintf(stderr, " %-32sComment\n", "Username");
+ fprintf(stderr, " %-32s Comment\n", "Username");
while (key.dptr != NULL) {
rv = apr_dbm_fetch(htdbm->dbm, key, &val);
if (rv != APR_SUCCESS) {
fprintf(stderr, "Failed getting data from %s\n", htdbm->filename);
return APR_EGENERAL;
}
- kb = apr_pstrndup(htdbm->pool, key.dptr, key.dsize);
- fprintf(stderr, " %-32s", kb);
- rec = apr_pstrndup(htdbm->pool, val.dptr, val.dsize);
- cmnt = strchr(rec, ':');
+ /* Note: we don't store \0-terminators on our dbm data */
+ fprintf(stderr, " %-32.*s", key.dsize, key.dptr);
+ cmnt = memchr(val.dptr, ':', val.dsize);
if (cmnt)
- fprintf(stderr, "%s", cmnt + 1);
+ fprintf(stderr, " %.*s", val.dptr+val.dsize - (cmnt+1), cmnt + 1);
fprintf(stderr, "\n");
rv = apr_dbm_nextkey(htdbm->dbm, &key);
if (rv != APR_SUCCESS)