delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/30/22:45:44

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help - Are these pointer quirks unique to C++ or my compiler?
Date: Tue, 30 Dec 1997 21:21:40 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 34
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <34A9AC33.68EA187B@cornell.edu>
References: <34A9D94B DOT 7A3D AT ns DOT sympatico DOT ca>
NNTP-Posting-Host: cu-dialup-0008.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Visionary wrote:
<snip>
>         Also, I couldn't use the parameter "compoundMode" directly as 
> in:
> 
>            newCompoundMode = strlwr(&compoundMode);
> 
>         This gives me the above mentioned crash and burn as well. Any 
> ideas on either of these two weird quirks?

why is it that every time someone makes a mistake it is a 'quirk'?

compoundMode is a single char. strlwr expects a char * to a
null-terminated string. when you pass it the address of that single
char, there is no guarantee that the next byte will contain '\0'. so, if
that value is not '\0', strlwr continues to convert to lower case,
overwiriting memory locations until it meets a '\0'. when it runs into
one depends on how the variables are laid out in memory. so, you get a
crash in one case, and not in the other. the code is equally wrong in
either case.

by the way, why not use the ANSI function tolower whose purpose is to
convert characters to lower case?

info libc alpha tolower
info libc alpha toupper
-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019