+2009-04-14 John Stanley <jpsinthemix@verizon.net>
+ David S. Miller <davem@davemloft.net>
+
+ * util/hostdisk.c (make_device_name): Fix buffer length
+ calculations.
+
2009-04-14 Felix Zielcke <fzielcke@z-51.de>
* util/hostdisk.c [__FreeBSD__ || __FreeBSD_kernel__]: Include
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)