Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!aurora!labrea!decwrl!hplabs!hpda!hpscda!hpqtdla!hpopda!mik From: mik@hpopda.HP.COM (Mik Butler) Newsgroups: comp.lang.c Subject: Re: QuickC bug Message-ID: <580003@hpopda.HP.COM> Date: 10 Jan 88 18:22:45 GMT References: <2242@cup.portal.com> Organization: HP OPD, Pinewood, UK Lines: 57 Walt Novinger writes : > > I have found and reported to MicroSoft the following bugs in the > QuickC v1.0 `_splitpath` function and its documentation. The > code fragment below illustrates the code which will reproduce > the bug. The following describes the problems: . . . > 3) The bug, which can be observed under the debugger, is > that the first character of the `prog` variable is left > as a null. For instance, if the string "d:\\tmp\\bazfaz.exe" > is fed to the function, `prog` will contain "\0azfaz\0\0\0" > on return. The rest of the variables are correctly set. > > ========================= Example Program ================================= > #include > #include > > /* get program name from DOS, extract base name and convert to lowercase */ > > char *progname(pathname) > char pathname[40]; > { > char drive[3]; /* note that `*` is *incorrect* */ > char dir[60]; > char prog[9]; > char ext[4]; > char *result; > > _splitpath(pathname, drive, dir, prog, ext); > result = strlwr(prog); /* convert to lowercase */ > return (result); > } > > > main(argc, argv) > int argc; > char *argv[]; > { > char *pro; > > pro = progname(argv[0]); /* extract program name w/o extension */ . . The reason that this fails isn't because _splitpath is broken, its because progname is returning a pointer to something that is no longer in scope. The space for prog is allocated on the stack for the lifetime of progname, so pro will point to the space where prog was (and now isn't). If the declaration is changed to 'static char prog[9];', then the example program will work. Alternately, make the declaration 'char prog[9];' global. ---------------------------------------- Mik Butler