K
kevin
Hi everyone. I'm scratching my head and can't understand why I'm
getting a warning from splint on this bit of code:
1 #include <stdio.h>
2 #include <ctype.h>
3
4 static char *strtolower( char *str )
5 {
6 char *s;
7
8 for ( s = str; *s; ++s )
9 *s = tolower( *s );
10
11 return str;
12 }
13
14 int main( void )
15 {
16 char msg[] = "Hello world";
17
18 printf( "%s\n", strtolower( msg ) );
19 return 0;
20 }
$ splint test.c
Splint 3.1.1 --- 03 Sep 2009
test.c: (in function strtolower)
test.c:8:20: Test expression for for not boolean, type char: *s
Test expression type is not boolean. (Use -predboolothers to inhibit warning)
test.c:11:12: Implicitly temp storage str returned as implicitly only: str
Temp storage (associated with a formal parameter) is transferred to a
non-temporary reference. The storage may be released or new aliases created.
(Use -temptrans to inhibit warning)
test.c: (in function main)
test.c:18:21: New fresh storage (type char *) passed as implicitly temp (not
released): strtolower(msg)
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
Finished checking --- 3 code warnings
$ gcc -ansi -pedantic -Wall test.c -o test
$ ./test
hello world
$
Okay, so splint warns me that it has detected a memory leak in the
printf call, which
itself calls the function strtolower. I can't see it - I am only
returning the same address
that was passed to the function as a parameter. No new memory is being
allocated, so I
cannot understand why there would be a memory leak?
Can any one guide me on why there's a memory leak here? How do I
correct it or code
around it?
Or is splint in error?
TIA-
Kevin
getting a warning from splint on this bit of code:
1 #include <stdio.h>
2 #include <ctype.h>
3
4 static char *strtolower( char *str )
5 {
6 char *s;
7
8 for ( s = str; *s; ++s )
9 *s = tolower( *s );
10
11 return str;
12 }
13
14 int main( void )
15 {
16 char msg[] = "Hello world";
17
18 printf( "%s\n", strtolower( msg ) );
19 return 0;
20 }
$ splint test.c
Splint 3.1.1 --- 03 Sep 2009
test.c: (in function strtolower)
test.c:8:20: Test expression for for not boolean, type char: *s
Test expression type is not boolean. (Use -predboolothers to inhibit warning)
test.c:11:12: Implicitly temp storage str returned as implicitly only: str
Temp storage (associated with a formal parameter) is transferred to a
non-temporary reference. The storage may be released or new aliases created.
(Use -temptrans to inhibit warning)
test.c: (in function main)
test.c:18:21: New fresh storage (type char *) passed as implicitly temp (not
released): strtolower(msg)
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
Finished checking --- 3 code warnings
$ gcc -ansi -pedantic -Wall test.c -o test
$ ./test
hello world
$
Okay, so splint warns me that it has detected a memory leak in the
printf call, which
itself calls the function strtolower. I can't see it - I am only
returning the same address
that was passed to the function as a parameter. No new memory is being
allocated, so I
cannot understand why there would be a memory leak?
Can any one guide me on why there's a memory leak here? How do I
correct it or code
around it?
Or is splint in error?
TIA-
Kevin