TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Phil Crown
from: David Nugent
date: 1995-02-05 18:16:16
subject: EMX strtok bug!

> I think I've found a bug in EMX's strtok() function.  Below compiles and
 > runs fine under Turbo C/C++, but crashes at the first call to
 > strtok() under emx.
~
 > VOID  stoi_znnp( CHAR *Address )
 > {
 >   CHAR            *ptr;
 >   const   CHAR    *seps       =   ":/."   ;
 >   SHORT            count      =   0       ;

 >   ptr = strtok( Address, seps );    // crashes at this line
~
 >   stoi_znnp( "1:124/6108" );


Whoops! No, not a compiler bug. It's a feature of your protected mode
environment and emx. :-)

Literal strings are (sensibly) placed into read-only memory, and strtok()
modifies the string, placing NULs into it. Either dupe the string within
the stoi_znnp() function or copy it to a temp buffer before passing to it.

Of course, it "works" under TurboC in real mode without any
memory protection. Had you used the strings more than once in your program
and if you had elected to fold string literals you would, however, run into
problems immediately.


   regards,
   david

---
* Origin: Unique Computing, Melbourne, Australia (3:632/348)
SEEN-BY: 12/2442 620/243 624/50 632/103 301 341 348 633/379 635/503 640/820
SEEN-BY: 690/660 711/409 410 413 430 807 808 809 934 942 949 955 712/515
SEEN-BY: 713/888 800/1 7877/2809
@PATH: 632/103 348 711/409 808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.