Thread View: comp.os.os2.programmer
3 messages
3 total messages
Started by Jay Troy
Wed, 22 Jul 1992 14:36
EMX library bug.
Author: Jay Troy
Date: Wed, 22 Jul 1992 14:36
Date: Wed, 22 Jul 1992 14:36
30 lines
1168 bytes
1168 bytes
I think I've discovered an EMX library bug. The standard library function
strtok causes an access violation in every combination that I've tried. The
following simple C program illustrates this problem:
---cut here---
#include <stdlib.h>
#include <string.h>
#include <math.h>
main()
{
char temp[10];
char *ch = "3.4 4.1";
printf("ch = %s\n",ch);
strcpy(temp, strtok(ch," "));
printf("temp = %s\n",temp);
}
---cut here---
I guess I'll start to look at the library source. If anyone already has
this problem fixed or wants more info, please email me. Thanks.
Jay Troy Delaware Valley Solution Systems, Inc.
Computing Solutions for Business and Industry
P.O. Box 190 // Claymont, DE 19703 // (302)798-DVSS
Internet: ...!udel.edu!dvss!jtroy (jtroy@dvss.UUCP)
--
Re: EMX library bug.
Author: Colin Jensen
Date: Wed, 22 Jul 1992 18:53
Date: Wed, 22 Jul 1992 18:53
21 lines
1430 bytes
1430 bytes
In article <ReiBoB5w164w@dvss.UUCP> dvss!jtroy@udel.edu (Jay Troy) writes: >I think I've discovered an EMX library bug. The standard library function >strtok causes an access violation in every combination that I've tried. The >following simple C program illustrates this problem: > char *ch = "3.4 4.1"; > strcpy(temp, strtok(ch," ")); I don't know anything about EMX, but your code is certainly problematic. A C compiler is free to store strings constants like "3.4 4.1" in read-only memory [hence their name]. Since strtok will try to write into that memory, an access violation should be expected. To be portable, you need to copy that string either into an automatic variable or copy it into some malloc'ed memory. Under UNIX, you can pass gcc the option -fwritable-strings to tell gcc you really want to be able to write into string constants. Perhaps this would solve your problem with EMX. -- Colin Jensen (cjensen@ampex.com)
Re: EMX library bug.
Author: Kai-Uwe Rommel
Date: Thu, 23 Jul 1992 07:33
Date: Thu, 23 Jul 1992 07:33
31 lines
1892 bytes
1892 bytes
In article <1992Jul22.185306.10692@ampex.com> cjensen@ampex.com (Colin Jensen) writes: >In article <ReiBoB5w164w@dvss.UUCP> dvss!jtroy@udel.edu (Jay Troy) writes: >>I think I've discovered an EMX library bug. The standard library function >>strtok causes an access violation in every combination that I've tried. The >>following simple C program illustrates this problem: > >> char *ch = "3.4 4.1"; >> strcpy(temp, strtok(ch," ")); > >I don't know anything about EMX, but your code is certainly problematic. >A C compiler is free to store strings constants like "3.4 4.1" in >read-only memory [hence their name]. Since strtok will try to write >into that memory, an access violation should be expected. > >To be portable, you need to copy that string either into an automatic variable >or copy it into some malloc'ed memory. > >Under UNIX, you can pass gcc the option -fwritable-strings to tell gcc you >really want to be able to write into string constants. Perhaps this would >solve your problem with EMX. >-- >Colin Jensen (cjensen@ampex.com) Yes, -fwritable-strings solves this problem. Try it. Kai Uwe Rommel /* Kai Uwe Rommel --- rommel@informatik.tu-muenchen.de */ DOS ... is still a real mode only non-reentrant interrupt handler, and always will be. -Russell Williams
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads