Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!newstop!sun!rushforth!kcr From: kcr%rushforth@Sun.COM (Kevin Rushforth) Newsgroups: comp.sources.games.bugs Subject: Re: Ularn bug -- selling the same gem more than once Message-ID: <115011@sun.Eng.Sun.COM> Date: 12 Jul 89 04:04:58 GMT References: <114443@sun.Eng.Sun.COM> <34458@bu-cs.BU.EDU> Sender: news@sun.Eng.Sun.COM Reply-To: kcr@sun.UUCP (Kevin Rushforth) Organization: Sun Microsystems, Mountain View Lines: 53 In article <34458@bu-cs.BU.EDU> adb@bu-cs.bu.edu (Adam Bryant) writes: >In article <114443@sun.Eng.Sun.COM> kcr%rushforth@Sun.COM (Kevin Rushforth) writes: >>There is a bug in larn that was carried over into Ularn which allows >>one to sell a gem an unlimited number of times. To reproduce this > >You really don't need to create the extra loop to fix that bug. >The array gemvalue is declared as a static array and therefore saves >its value between calls to the function. > >Simply remove the word 'static' from the declaration of gemvalue >and the problem will be solved. Not quite. Here is the relevant piece of store.c ------------------------------ static short gemorder[26]={0}; /* the reference to screen location for each */ static long gemvalue[26]={0}; /* the appraisal of the gems */ obanksub() { long amt; register int i,k; ointerest(); /* credit any needed interest */ if (level==8) c[TELEFLAG] = 0; /****** HERE IS THE LOOP TO INITIALIZE THE ARRAY ******/ for(i = 0; i < 26; i++) gemvalue[i] = 0; /****** END OF THE LOOP TO INITIALIZE THE ARRAY ******/ for (k=i=0; i<26; i++) switch(iven[i]) { [...more stuff...] Since the array is declared outside the obanksub() routine, removing the word static would not change the fact that the array keeps its value between calls to the function. All that it would do is make the global array gemvalue[] externally visible (not a good idea unless you have a reason). Even if you were to move the array declaration into the obanksub() function and then remove the 'static' keyword, you would still have to initialize it. Automatic variables in "C" (including arrays) are not initialized upon entry into a function. The patch that I posted is the easiest way around the bug without modifying the logic of the routine. -- Kevin C. Rushforth | "If winning is not important, Sun Microsystems | then commander, why keep score?" | - Lt. Worf ARPA: kcr@sun.com | UUCP: !sun!kcr |