Browse Source

make more use of nfstrndup()

wip/uidval-recovery
Oswald Buddenhagen 8 years ago
parent
commit
3b615bba3c
  1. 20
      src/drv_imap.c
  2. 8
      src/drv_maildir.c

20
src/drv_imap.c

@ -420,13 +420,8 @@ imap_vprintf( const char *fmt, va_list ap )
oob(); oob();
memcpy( d, s, l ); memcpy( d, s, l );
d += l; d += l;
if (!c) { if (!c)
l = d - buf; return nfstrndup( buf, d - buf );
ed = nfmalloc( l + 1 );
memcpy( ed, buf, l );
ed[l] = 0;
return ed;
}
maxlen = INT_MAX; maxlen = INT_MAX;
c = *++fmt; c = *++fmt;
if (c == '\\') { if (c == '\\') {
@ -773,9 +768,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
*d++ = c; *d++ = c;
} }
cur->len = d - p; cur->len = d - p;
cur->val = nfmalloc( cur->len + 1 ); cur->val = nfstrndup( p, cur->len );
memcpy( cur->val, p, cur->len );
cur->val[cur->len] = 0;
} else { } else {
/* atom */ /* atom */
p = s; p = s;
@ -785,11 +778,8 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
cur->len = s - p; cur->len = s - p;
if (equals( p, cur->len, "NIL", 3 )) if (equals( p, cur->len, "NIL", 3 ))
cur->val = NIL; cur->val = NIL;
else { else
cur->val = nfmalloc( cur->len + 1 ); cur->val = nfstrndup( p, cur->len );
memcpy( cur->val, p, cur->len );
cur->val[cur->len] = 0;
}
} }
next: next:

8
src/drv_maildir.c

@ -1033,7 +1033,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
fnl = (u ? fnl = (u ?
nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%.*s,U=%d%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) : nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%.*s,U=%d%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) :
nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s,U=%d", subdirs[entry->recent], entry->base, uid )) nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s,U=%d", subdirs[entry->recent], entry->base, uid ))
+ 1 - 4; - 4;
memcpy( nbuf, buf, bl + 4 ); memcpy( nbuf, buf, bl + 4 );
nfsnprintf( nbuf + bl + 4, sizeof(nbuf) - bl - 4, "%s", entry->base ); nfsnprintf( nbuf + bl + 4, sizeof(nbuf) - bl - 4, "%s", entry->base );
if (rename( nbuf, buf )) { if (rename( nbuf, buf )) {
@ -1048,8 +1048,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
goto again; goto again;
} }
free( entry->base ); free( entry->base );
entry->base = nfmalloc( fnl ); entry->base = nfstrndup( buf + bl + 4, fnl );
memcpy( entry->base, buf + bl + 4, fnl );
} }
if (ctx->gen.opts & OPEN_SIZE) { if (ctx->gen.opts & OPEN_SIZE) {
if (stat( buf, &st )) { if (stat( buf, &st )) {
@ -1571,8 +1570,7 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, int uid ATTR_UNUSED, int
} }
} }
free( msg->base ); free( msg->base );
msg->base = nfmalloc( tl + 1 ); msg->base = nfstrndup( nbuf + bl, tl );
memcpy( msg->base, nbuf + bl, tl + 1 );
msg->gen.flags |= add; msg->gen.flags |= add;
msg->gen.flags &= ~del; msg->gen.flags &= ~del;
gmsg->status &= ~M_RECENT; gmsg->status &= ~M_RECENT;

Loading…
Cancel
Save