From: amylaar@meolyon.hanse.de (Joern Rennecke) Subject: Re: gcc, pl6, ext2fs, and my C code Date: Mon, 29 Mar 1993 06:36:57 GMT
jblaine@garnet.acns.fsu.edu (C. Jefferson Blaine) writes:
>With SLS linux 0.99pl6, gcc 2.3.3, and a main 71meg linux extended
I have SLS last change 17th Feb 1993 and kernel 0.99p6 with xiafs. gcc is 2.3.3,
libc is 4.3 . Root partition is minix, working directory was xiafs.
After deleting a single line, the code worked.
>partition, the following code goes into an infinite loop, spewing
>my printf debugging messages to the screen with values of "0" and ";"
>instead of actual english like strings and then ending.
>This code works fine with AIX 3.2 and other OSs that I have it compiled
>on. It is a simple loop that opens a file associated with the filename
>passed to the function (which is being passed correctly), and reads
>in lines of the file into a multi-level linked list and then returns.
>the file to be loaded has the form:
>OBJ:
>object1
>attribute1 value1
>attribute2 value2
>....
>OBJ:
>object2
>attribute1 value1
>attribute2 value2
>...
>/* LOADDB */
>int loaddb (char *fname)
>{
>FILE *fp;
>char temp[80], temp2[80];
>char object[30];
>if (strlen(fname) == 0) {
> printf("error: No filename provided.\n");
> return(0);
>}
>fname[strlen(fname)-1]='\0';
^This line needed to be deleted. It writes into the argument, which happened to
be in the text segment for me... it dosn't make sense anyways.
>printf("In loaddb. fname is %s\n", fname);
>if ((fp = fopen(fname, "r")) == NULL) {
> printf("error: file \"%s\" not found.\n", fname);
> fclose(fp);
> return(0);
>}
>while (!feof(fp)) {
> fgets (temp, 80, fp);
> printf ("Line gotten: %s\n", temp);
> if (!strcmp (temp, "OBJ:\n")) {
> fgets (object, 30, fp);
end-of-file check missing. You can get NULL here.
also missing: object[sizeof object - 1] = '\0';
> printf("Adding object: %s\n", object);
> addobj (object);
> } else {
> fgets (temp, 80, fp);
end-of-file check missing.
also missing: temp[sizeof temp - 1] = '\0';
> strcpy (temp2, object);
29
> strcat (temp2, " ");
+1
> strcat (temp2, temp);
+80 = 110 ==> temp2 should be declared as char temp2[110];
> printf ("Calling addatt with: %s\n", temp2);
> addatt (temp2);
> }
>}
>fclose(fp);
>return(1);
>}
Joern Rennecke