This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/10138] warn for uninitialized arrays passed as const* arguments
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Aug 2007 16:15:27 -0000
- Subject: [Bug middle-end/10138] warn for uninitialized arrays passed as const* arguments
- References: <bug-10138-1038@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #15 from manu at gcc dot gnu dot org 2007-08-20 16:15 -------
(In reply to comment #14)
> This is meant to only counter your point that:
> > 'const' does not mean read-only in C++ at all, and much less in C. atoi(const
> > char *) could always initialize buf[].
> This simply isn't true. In C++, atoi can't do that.
>
Please, take a look at the example given by Andrew
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086#c3. I can compile and run a
similar example:
#include <cstdio>
void use(const int *a)
{
int * b = (int *)a;
b[0] = 5;
}
int main(void)
{
int i=0;
use(&i);
printf("%d\n", i);
return 0;
}
Of course, the output is '5' and not '0'. So yes, atoi() seems perfectly able
to initialize buf. (or perhaps, I am still confused).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10138