Fixes the amount of allocated memory for ttypath, so that there is place for '\0'.
Removes unnecessary * sizeof(char) operation. Signed-off-by: Yegor Yefremov <[email protected]> Index: b/can-utils/slcand.c =================================================================== --- a/can-utils/slcand.c 2011-01-05 10:13:25.000000000 +0100 +++ b/can-utils/slcand.c 2011-01-06 11:05:31.000000000 +0100 @@ -100,7 +100,10 @@ char const *pidprefix = "/var/run/"; char const *pidsuffix = ".pid"; char *pidfile; - pidfile = malloc((strlen(pidprefix) +strlen(DAEMON_NAME) + strlen(tty) + strlen(pidsuffix) + 1) * sizeof(char)); + + /* allocate memory for pidfile: + * length of file name parts and 1 for '\0' */ + pidfile = malloc(strlen(pidprefix) + strlen(DAEMON_NAME) + strlen(tty) + strlen(pidsuffix) + 1); sprintf(pidfile, "%s%s-%s%s", pidprefix, DAEMON_NAME, tty, pidsuffix); /* already a daemon */ @@ -235,7 +238,10 @@ if (pch == tty) { print_usage(argv[0]); } - ttypath = malloc((strlen(devprefix) + strlen(tty)) * sizeof(char)); + + /* allocate memory for ttypath: + * length of "/dev/" + length of tty device and 1 for '\0' */ + ttypath = malloc(strlen(devprefix) + strlen(tty) + 1); sprintf (ttypath, "%s%s", devprefix, tty); syslog (LOG_INFO, "starting on TTY device %s", ttypath); _______________________________________________ Socketcan-core mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-core
