home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14759 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  1.7 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!swrinde!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!kth.se!dront.nada.kth.se!d88-jwa
  2. From: d88-jwa@dront.nada.kth.se (Jon W{tte)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Inconsistantcy in Think C
  5. Message-ID: <D88-JWA.92Aug30221950@dront.nada.kth.se>
  6. Date: 30 Aug 92 21:19:50 GMT
  7. References: <1992Aug30.091804.1@acad2.alaska.edu>
  8. Sender: usenet@kth.se (Usenet)
  9. Organization: Royal Institute of Technology, Stockholm, Sweden
  10. Lines: 35
  11. In-Reply-To: asmah@acad2.alaska.edu's message of 30 Aug 92 13:18:04 GMT
  12. Originator: d88-jwa@dront.nada.kth.se
  13. Nntp-Posting-Host: dront.nada.kth.se
  14.  
  15. > asmah@acad2.alaska.edu writes:
  16.  
  17.    I have a sprintf() statement which doesn't work the first time through, but
  18.    works during a second time.  As far as I can tell, all the variables are
  19.    identical during both passes.  This is what it looks like.
  20.  
  21.    CharsHandle  input;
  22.    TEHandle TEFields[20];
  23.  
  24.    input = TEGetText(TEFields[0]);
  25.    sprintf((**ARH.c_employee).last_name,"%.*s",(**TEFields[0]).teLength,(**input));
  26.    return 1;
  27.  
  28. Are you sure it says **input? Since that would be a char, not a char
  29. pointer, as you would want when passing %s.
  30.  
  31. Anyway, you are probably calling sprintf from another segment which
  32. makes a segment load which moves memory which makes your de-referenced
  33. handle move. Lock it first:
  34.  
  35.     char state ;
  36.  
  37.     input = ....
  38.     state = HGetState ( input ) ;
  39.     HLock ( state ) ;
  40.     sprintf ( ... ) ;
  41.     HSetState ( input , state ) ;
  42.  
  43.  
  44. More about this in the chapter about the memory manager in IM II.
  45.  
  46. -- 
  47. Jon W{tte, h+@nada.kth.se, Sweden, Phone +46-8-107069
  48. White, Literate, Employed, Higher-Educated, Male, Straight and Not Poor.
  49. I must be a bad guy.
  50.