TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Mark Kimes
from: Chris Mcbrien
date: 1994-07-23 04:03:44
subject: Re: Simple Problem

Hi Mark,

 CM>I am trying to compile the following code, but I ALWAYS gives me a
 CM>General Protection fault at the SPRINTF call:

 CM>      char    String[255];

 MK>           if(InstanceData.ptrUserProfile)
 CM>        sprintf(String,"Your user number is %lx",
 MK>                     InstanceData.ptrUserProfile->ulUserNumber);
 MK>           else
 MK>             sprintf(String,"NULL pointer line %lu,
dufus!",__LINE__);

 MK> Be sure to initialize InstanceData.ptrUserProfile to NULL and
 MK> reinitialize to NULL if what it points at becomes invalid (like if you
 MK> free it).

Actually, it turned out to be a very strange problem.  I was calling a
function long before this code is run, that assignes a character to a
variable defined as
        char Temp;

Well, if I simply recode this to be:
        char Temp[255];

The problem with sprintf many, many lines, of code, and several functions
later, disappears.

Could this be a C/SET bug, or just a very odd artifact of what I was doing?

Either way, problem solved.  Thanks for your suggestion.

I hope my little experience can help someone someday.

Take care,
    Chris


--- Maximus/2 2.01wb

* Origin: Upper Echelons BBS Calgary (403) 246-6329 (1:134/23)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 413 430
SEEN-BY: 711/807 808 809 934 942 712/353 623 713/888 800/1
@PATH: 134/23 17 3615/50 229/2 12/2442 711/409 54/54 711/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™.