Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!integral!dhare From: dhare%integral@Sun.COM (Dwight Hare) Newsgroups: comp.sys.mac.programmer Subject: Re: A strange MPW bug (mine, not Apple's) Message-ID: <54996@sun.uucp> Date: 1 Jun 88 01:08:10 GMT References: <2554@mit-amt.MEDIA.MIT.EDU> Sender: news@sun.uucp Reply-To: dhare@sun.UUCP (Dwight Hare) Organization: Sun Microsystems, Mountain View Lines: 23 In article <2554@mit-amt.MEDIA.MIT.EDU> phil@mit-amt.MEDIA.MIT.EDU (Phil Sohn) writes: >I have a really weird bug, does anyone have an idea what is going on? >In the following code segment there are two bugs. The first one is I >can not seem to get a string back out of a structure once I put it there. >The second one is DebugStr does not seem to work like I think it should. > DebugStr(strcat("On entry title is ", title)); /* This to */ > DebugStr("The struct title is "); /* This prints garbage i.e. > the value of title followed by ssssDrawScrollBar() */ This is an ordinary C programming mistake. Strcat appends to the string by writing over the terminating zero and continuing on. There is no concept of extending the string. Since the string provided has no space alloted for appending, the title writes over whatever follows the string in memory, which appears to be the string used in the next DebugStr call. Once you overwrite memory, everything gets confused. To do what you want would require: char str[100]; strcpy(str, "On entry title is "); strcat(str, title); DebugStr(str);