diff --git a/ChangeLog b/ChangeLog index 28657554d..9c51eefe1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-04-14 John Stanley + David S. Miller + + * util/hostdisk.c (make_device_name): Fix buffer length + calculations. + 2009-04-14 Felix Zielcke * util/hostdisk.c [__FreeBSD__ || __FreeBSD_kernel__]: Include diff --git a/util/hostdisk.c b/util/hostdisk.c index 1825ac07b..2fd1010a2 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -656,11 +656,21 @@ make_device_name (int drive, int dos_part, int bsd_part) char *p; if (dos_part >= 0) - len += 1 + ((dos_part + 1) / 10); + { + /* Add in char length of dos_part+1 */ + int tmp = dos_part + 1; + len++; + while ((tmp /= 10) != 0) + len++; + } if (bsd_part >= 0) len += 2; - p = xmalloc (len); + /* Length to alloc is: char length of map[drive].drive, plus + * char length of (dos_part+1) or of bsd_part, plus + * 2 for the comma and a null/end of string (\0) + */ + p = xmalloc (len + 2); sprintf (p, "%s", map[drive].drive); if (dos_part >= 0)