mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-23 22:53:35 +00:00
Btrfs-progs: don't allocate one byte too much each time
str1 + '/' + str2 + '\0' requires a buffer with the size strlen(str1) + strlen(str2) + 2 bytes. str1 + '/' + str2 + '/' + str3 + '\0' requires a buffer with the size strlen(str1) + strlen(str2) + strlen(str3) + 3 bytes. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
This commit is contained in:
parent
46de1a6ec3
commit
7c04a4444e
@ -332,7 +332,7 @@ char *path_cat(const char *p1, const char *p2)
|
||||
{
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
char *new = malloc(p1_len + p2_len + 3);
|
||||
char *new = malloc(p1_len + p2_len + 2);
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
@ -348,7 +348,7 @@ char *path_cat3(const char *p1, const char *p2, const char *p3)
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
int p3_len = strlen(p3);
|
||||
char *new = malloc(p1_len + p2_len + p3_len + 4);
|
||||
char *new = malloc(p1_len + p2_len + p3_len + 3);
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
|
Loading…
Reference in New Issue
Block a user