|
Home > Archive > Unix Programming > November 2007 > core dump for str
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Solaris 5.8 is throwing core dump for the following code:
strcasecmp(str1,"NULL);
Could any one specify the reason for the same, it would be helpful?
gdb
#0 0xff14f2f4 in strcasecmp ()
(gdb) where
#0 0xff14f2f4 in strcasecmp ()
| |
| Ulrich Eckhardt 2007-11-16, 7:34 am |
| harry wrote:
> Solaris 5.8 is throwing core dump for the following code:
>
> strcasecmp(str1,"NULL);
Any decent compiler wouldn't even let this pass. I could elaborate on why,
but I suggest you provide a complete example rather, which is minimal and
compiles.
Lastly, strcasecmp needs two strings, a null pointer isn't a string.
Uli
| |
| Joachim Schmitz 2007-11-16, 7:34 am |
| "harry" <harishgowda84@gmail.com> schrieb im Newsbeitrag
news:ed83d541-31d8-469a-94b1-0ad8ed608caa@d4g2000prg.googlegroups.com...
> Solaris 5.8 is throwing core dump for the following code:
>
> strcasecmp(str1,"NULL);
And that code did pass the compiler???
> Could any one specify the reason for the same, it would be helpful?
>
> gdb
>
> #0 0xff14f2f4 in strcasecmp ()
> (gdb) where
> #0 0xff14f2f4 in strcasecmp ()
strcasecmp(str1, "NULL") should work, as long as str1 points to a string.
strcasecmp(str1, NULL) would probably fail, as I don't believe strcasecmp
checks it's args for NULL pointers, but just tries to derefference
them ->KABOOM
Bye, Jojo
| |
|
| On Nov 16, 2:04 pm, Ulrich Eckhardt <dooms...@knuut.de> wrote:
> harry wrote:
>
>
> Any decent compiler wouldn't even let this pass. I could elaborate on why,
> but I suggest you provide a complete example rather, which is minimal and
> compiles.
>
> Lastly, strcasecmp needs two strings, a null pointer isn't a string.
>
> Uli
Thanks,
this is just the sample code ,not all but with function and it's
paramters
int
get_grp_mnulist(groupname,application, spool_fp)
char *groupname;
char application[PBG_MAXAPPIDLEN];
{
....................
if (strcasecmp(groupname, "NULL") != 0 &&
(strlen(groupname) > 0))
{
/* Group name received in request packet */
/* Get group mask for it */
memset(tmpmsk, 0, sizeof(tmpmsk));
iRetValue = getgrpmsk(groupname, tmpmsk);
//printf("get_grp_mnulist : getgrpmsk ret. val <%d>\n",
iRetValue);
if (iRetValue < 0)
{
// printf("get_grp_mnulist : Failed in getting group
mask.No such group");
return(-1);
}
..................................
}
..................................
}
core dump is as follows:
Reading symbols from /usr/platform/SUNW,Sun-Fire-880/lib/libc_psr.so.
1...(no debugging symbols found)...done.
#0 0xff14f2f4 in strcasecmp ()
(gdb) where
#0 0xff14f2f4 in strcasecmp ()
#1 0x2772c in get_grp_mnulist ()
#2 0x1ff6c in SpoolGroup ()
#3 0x1dadc in main ()
Cannot access memory at address 0x4d41547b.
.....
It would be helpful if you suggest something..
| |
| Joachim Schmitz 2007-11-16, 7:34 am |
| "harry" <harishgowda84@gmail.com> schrieb im Newsbeitrag
news:bf46d98f-52ba-4472-aee9-e969ca648130@a39g2000pre.googlegroups.com...
> On Nov 16, 2:04 pm, Ulrich Eckhardt <dooms...@knuut.de> wrote:
>
>
> Thanks,
>
> this is just the sample code ,not all but with function and it's
> paramters
>
>
> int
> get_grp_mnulist(groupname,application, spool_fp)
> char *groupname;
> char application[PBG_MAXAPPIDLEN];
> {
> ...................
>
> if (strcasecmp(groupname, "NULL") != 0 &&
Check gropname here
if (groupname && strcasecmp(groupname, "NULL") != 0 &&
If that doesn't help, step till there in gdb and display it's value
> (strlen(groupname) > 0))
> {
> /* Group name received in request packet */
> /* Get group mask for it */
> memset(tmpmsk, 0, sizeof(tmpmsk));
> iRetValue = getgrpmsk(groupname, tmpmsk);
> //printf("get_grp_mnulist : getgrpmsk ret. val <%d>\n",
> iRetValue);
> if (iRetValue < 0)
> {
> // printf("get_grp_mnulist : Failed in getting group
> mask.No such group");
> return(-1);
> }
>
> ..................................
> }
> .................................
> }
>
>
> core dump is as follows:
>
> Reading symbols from /usr/platform/SUNW,Sun-Fire-880/lib/libc_psr.so.
> 1...(no debugging symbols found)...done.
> #0 0xff14f2f4 in strcasecmp ()
> (gdb) where
> #0 0xff14f2f4 in strcasecmp ()
> #1 0x2772c in get_grp_mnulist ()
> #2 0x1ff6c in SpoolGroup ()
> #3 0x1dadc in main ()
> Cannot access memory at address 0x4d41547b.
>
>
> ....
>
> It would be helpful if you suggest something..
Bye, Jojo
| |
| Ulrich Eckhardt 2007-11-16, 7:34 am |
| harry wrote:
> this is just the sample code ,not all but with function and it's
> paramters
Well, you are supposet to reduce it to the bare minimum. Nobody here wants
to wade through lots of code that isn't even complete.
> int
> get_grp_mnulist(groupname,application, spool_fp)
> char *groupname;
> char application[PBG_MAXAPPIDLEN];
> {
This is not valid C. Please get a book on C and read how a function
definition looks like. The above syntax is old and non-standard, any recent
compiler should complain about it.
> if (strcasecmp(groupname, "NULL") != 0 &&
> (strlen(groupname) > 0))
If you want to do that, add at least an assert(groupname) and document the
function accordingly. Note that this has pretty little do do with
strcasecmp or strlen but is just general programming in C, i.e. that you
sometimes accept pointers but not null pointers and that if you receive a
pointer, that it must point to a valid object.
Uli
| |
| John Gordon 2007-11-16, 1:40 pm |
| In <bf46d98f-52ba-4472-aee9-e969ca648130@a39g2000pre.googlegroups.com> harry <harishgowda84@gmail.com> writes:
> char *groupname;
> {
> ...................
> if (strcasecmp(groupname, "NULL") != 0 &&
> (strlen(groupname) > 0))
My guess is that groupname is a null or invalid pointer.
As a debug, try printing the value of groupname before the strcasecmp.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
| |
| Geoff Clare 2007-11-19, 1:33 pm |
| Ulrich Eckhardt wrote:
>
> This is not valid C.
True, but perhaps not for the reason you think.
> The above syntax is old and non-standard,
The syntax is old (obsolescent), but not "non-standard". Compilers
conforming to the current C Standard (C99) are required to accept
function definitions using the obsolescent syntax.
The reason it is not valid C is because spool_fp is not declared.
It would have been valid C back when C89/90 was the standard, with
spool_fp assumed to have type int. C99 requires all of the
identifiers in the list to be declared. See 6.9.1 para 6:
"If the declarator includes an identifier list, each declaration
in the declaration list shall have at least one declarator, those
declarators shall declare only identifiers from the identifier list,
and every identifier in the identifier list shall be declared."
--
Geoff Clare <netnews@gclare.org.uk>
|
|
|
|
|