Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!mcnc!ethos!ducall!jeff From: jeff@ducall.UUCP Newsgroups: comp.sys.ibm.pc Subject: Bug in link - I think there's something to this! Message-ID: <373@ducall.UUCP> Date: Thu, 12-Mar-87 20:34:32 EST Article-I.D.: ducall.373 Posted: Thu Mar 12 20:34:32 1987 Date-Received: Sat, 14-Mar-87 10:02:51 EST Organization: none Lines: 56 [] Someone wrote recently about a problem with static arrays declared in different modules. Amazing cooincidence, I just came across the same type of problem with a static array in one module and malloced memory in another. The code goes something like the following. The compiler is Microsoft C. Procedures foo and bar are in different files. Both are compiled using the large memory model. They are two procedures in a rather large application, consisting of roughly 20 files and 200 procedures. struct BAR *first_link; foo() { char *malloc(); struct BAR *next_link; first_link = (struct BAR *)malloc(sizeof(struct BAR)); next_link = first_link; while (!done) { next_link->next = (struct BAR *)malloc(sizeof(struct BAR)); next_link = next_link->next; } } bar() { static char my_strings[10][128]; int i; for (i = 0; i < 128; i++) strcpy(my_strings[i],"STUNKY FLUFF\n"); } I am using the large memory model (I don't know if the problem persists in other models). The MSC User's Guide implies that the compiler puts my_strings in a _BSS segment. When I run the program procedure foo allocates memory, and runs right over the area that should have been reserved for my_strings. When bar executes, of course, the list structure is destroyed, as well as their contents, and the memory management info (i.e. program crashes in spectacular flames). As was the experience with the former observer, when I initialize my_strings the problem goes away - obviously because the compiler moves the array from the BSS section to the (initialized) data segment. This, however, is a kludge not a solution! Am I doing something wrong, or is there a bug in MSC malloc() such that (at least in the large memory model) one cannot have uninitialized global or static data. -- Jeffrey William Gillette uucp: mcnc!ethos!ducall!jeff Humanities Computing Facility bitnet: DYBBUK at TUCCVM Duke University