Path: utzoo!attcan!uunet!samsung!umich!yale!ox.com!metapyr!marc From: marc@metapyr.UUCP ( The Karate Kid ) Newsgroups: comp.windows.ms Subject: Re: Possible bug in tricky use of wsprintf - MSC 6.0 Message-ID: <960@metapyr.UUCP> Date: 19 Sep 90 14:01:03 GMT References: <6578@sugar.hackercorp.com> <57528@microsoft.UUCP> Reply-To: marc@metapyr.UUCP (Marc Paige - The Karate Kid ) Organization: Meta Systems, Ltd. -- Ann Arbor, MI Lines: 40 In article <57528@microsoft.UUCP> kensy@microsoft.UUCP (Ken SYKES) writes: >In article <6578@sugar.hackercorp.com> karl@hackercorp.com (Karl Lehenbauer) writes: >>Looks like wsprintfs of the form: >> >> wsprintf(outstr, "%.*s", numchars, text); >> >>...cause a trap. I'll be sure in a bit. In the meantime, beware. >>-- > >The * operator is not supported by wsprintf (look at the width description >in the SDK.) As a result it thinks numchars is the first part of the >string address then starts grabbing values from the bogus address. Thus >the fault. You could get around this by writing a replacement that >handles the '*' by using wsprintf to convert the control string to a static >string (replace *'s with the contents of numchar) then call wvsprintf to >do the actual command. Sloppy yes, but wsprintf is not documented as a >replacement for sprintf. Consequently some of the features may not be >provided. >Ken Sykes WHOA! The asterisk's got nothing to do with it! If Karl is using the medium model (as he should be :-( I hate the medium model) then the constant being passed by "%.*s" is a NEAR pointer. NEAR pointers passed to FAR pointer functions cause a trap 13. I ported a 2.11 program that had to use sprintf for the error message system. Converting all the sprintf's to wsprintf's made me painfully aware of this fact. Cast the "%.*s" to (LPSTR) and the trap should be gone. As a matter of fact, I just had to fix one of these little casts that I missed the first time. Caused "Unrecoverable Application Error". NOTE: All string arguments in the wsprintf call are LPSTR ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and must be either cast that way or generated by GlobalAlloc. This should help. Marc Paige Meta/LBMS ------------------------------------------------------------------------------ "tired and shagged out from a prolonged squawk" - mpfc the parrot sketch