mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 16:57:06 +00:00
Fix another charpool blunder: null goes at end of string, not end of allocation.
This commit is contained in:
parent
fb64aa9738
commit
fb29dba40e
1 changed files with 7 additions and 5 deletions
12
charpool.cc
12
charpool.cc
|
|
@ -106,14 +106,16 @@ void CharPool::clear(void) {
|
|||
}
|
||||
|
||||
const char *CharPool::dup(const char *src, int len) {
|
||||
int sz = len < 0 ? strlen(src) : len;
|
||||
if (len < 0)
|
||||
len = strlen(src);
|
||||
int sz = len + 1;
|
||||
char *p = buckets.back() + nexti;
|
||||
int modulus;
|
||||
|
||||
if ((modulus = sz % ALIGN_ON))
|
||||
sz += ALIGN_ON - modulus;
|
||||
|
||||
while (nexti + sz > currentbucketsz - 1) {
|
||||
while (nexti + sz > currentbucketsz) {
|
||||
/* Doh! We've got to make room */
|
||||
currentbucketsz <<= 1;
|
||||
nexti = 0;
|
||||
|
|
@ -121,7 +123,7 @@ const char *CharPool::dup(const char *src, int len) {
|
|||
buckets.push_back(p);
|
||||
}
|
||||
|
||||
nexti += sz + 1;
|
||||
p[sz] = '\0';
|
||||
return (const char *) memcpy(p, src, sz);
|
||||
nexti += sz;
|
||||
p[len] = '\0';
|
||||
return (const char *) memcpy(p, src, len);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue