On 01/06/2011 11:53 AM, Yegor Yefremov wrote:
> replace char pointers with static char buffers
> 
> 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:48:55.000000000 +0100
> @@ -63,6 +63,12 @@
>  /* Change this to the user under which to run */
>  #define RUN_AS_USER "root"
>  
> +/* The length of ttypath  */
> +#define TTYPATH_LENGTH       64
> +
> +/* The length of pidfile name */
> +#define PIDFILE_LENGTH       64
> +
>  #define EXIT_SUCCESS 0
>  #define EXIT_FAILURE 1
>  
> @@ -99,8 +105,8 @@
>       FILE * pFile;
>       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));
> +     char pidfile[PIDFILE_LENGTH];
> +
>       sprintf(pidfile, "%s%s-%s%s", pidprefix, DAEMON_NAME, tty, pidsuffix);
        ^^^^^^^

Use snprintf then.

>  
>       /* already a daemon */
> @@ -209,7 +215,7 @@
>  int main (int argc, char *argv[])
>  {
>       char *tty = NULL;
> -     char *ttypath;
> +     char ttypath[TTYPATH_LENGTH];
>       char const *devprefix = "/dev/";
>       char *name = NULL;
>       char buf[IFNAMSIZ+1];
> @@ -235,7 +241,7 @@
>       if (pch == tty) {
>               print_usage(argv[0]);
>       }
> -     ttypath = malloc((strlen(devprefix) + strlen(tty)) * sizeof(char));
> +
>       sprintf (ttypath, "%s%s", devprefix, tty);

dito

>       syslog (LOG_INFO, "starting on TTY device %s", ttypath);
>  
> 
> _______________________________________________
> Socketcan-core mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/socketcan-core

cheers, Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to