Re: [Nagios-devel] xodtemplate.c malloc question
Posted: Mon Dec 15, 2008 4:10 pm
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hiren wrote:
> just something I thought was odd, is the following diff valid?
> thanks.
>
>
> --- xdata/xodtemplate.c 2008-11-30 19:22:59.000000000 +0200
> +++ /tmp/xodtemplate.c 2008-12-15 16:45:58.000000000 +0200
> @@ -175,7 +175,7 @@
>
> /* allocate memory for 256 config files (increased dynamically) */
> xodtemplate_current_config_file=0;
> - xodtemplate_config_files=(char **)malloc(256*sizeof(char **));
> + xodtemplate_config_files=(char *)malloc(256*sizeof(char *));
> if(xodtemplate_config_files==NULL)
> return ERROR;
No. xodtemplate_config_files is an array of configuration file names.
The type here is correct, and it's declared and used as a char **
everywhere else. I think sizeof() should be of char * though, but that
doesn't really matter because pointer sizes are all the same no matter
what they represent.
P.s. There's also a similar realloc call to the same array.
- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJRoFv6dZ+Kt5BchYRAt9AAKDrdC2jvNgSQU41Ya18FYQMNFtxBgCg5oCb
M1UiqPtiY18kP4tUjkLJRgs=
=BWBc
-----END PGP SIGNATURE-----
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Hash: SHA1
hiren wrote:
> just something I thought was odd, is the following diff valid?
> thanks.
>
>
> --- xdata/xodtemplate.c 2008-11-30 19:22:59.000000000 +0200
> +++ /tmp/xodtemplate.c 2008-12-15 16:45:58.000000000 +0200
> @@ -175,7 +175,7 @@
>
> /* allocate memory for 256 config files (increased dynamically) */
> xodtemplate_current_config_file=0;
> - xodtemplate_config_files=(char **)malloc(256*sizeof(char **));
> + xodtemplate_config_files=(char *)malloc(256*sizeof(char *));
> if(xodtemplate_config_files==NULL)
> return ERROR;
No. xodtemplate_config_files is an array of configuration file names.
The type here is correct, and it's declared and used as a char **
everywhere else. I think sizeof() should be of char * though, but that
doesn't really matter because pointer sizes are all the same no matter
what they represent.
P.s. There's also a similar realloc call to the same array.
- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJRoFv6dZ+Kt5BchYRAt9AAKDrdC2jvNgSQU41Ya18FYQMNFtxBgCg5oCb
M1UiqPtiY18kP4tUjkLJRgs=
=BWBc
-----END PGP SIGNATURE-----
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]