delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/26/18:31:34

From: I1269U <i1269u AT my-deja DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: DJGPP specific strcpy() error
Date: Sat, 26 Jun 1999 21:36:26 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 74
Message-ID: <7l3h4p$7vt$1@nnrp1.deja.com>
NNTP-Posting-Host: 206.107.126.39
X-Article-Creation-Date: Sat Jun 26 21:36:26 1999 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
X-Http-Proxy: 1.1 x36.deja.com:80 (Squid/1.1.22) for client 206.107.126.39
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I wrote some code the other day at school that works fine for all three
different compilers that I use (MS Quick C, cc on VAX/VMS, and gcc on
UNIX). Essentially, I defined a structure with four strings, and a
pointer to a similar structure (ala linked list). Now, after gathering
the information to put into the four strings, I'd try to use strcpy()
to transfer the strings out of the local variables and into the
structure members. The code that I used looks something like this:

#include <stdio.h>
#include <string.h>

struct record {
    char ssn[10];  /* Social security # */
    char lname[21];  /* Last name */
    char fname[21];  /* First name */
    char dob[9];     /* Date of birth */
    struct record *next;  /* Point to next item in list */
};

typedef struct record RECORD;

main() {
    RECORD *testing;

    /* Structured this way for readability */
    /* Simulated input from user */
    char ssn[10] = "123456789";
    char lname[21] = "Smith";
    char fname[21] = "John";
    char dob[9] = "01/01/99";

    strcpy(testing->ssn, ssn);
    strcpy(testing->lname, lname);
    strcpy(testing->fname, fname);
    strcpy(testing->dob, dob);
}

/* End of code */

I would normally print this info or something, but it's useless at this
point, since I get kicked out of the program (at run time) when trying
to strcpy(). This only happens with DJGPP, and not with any other
compilers. Just so you know, it compiles and links just fine. Anyway, I
get an exit code of 255 (or 0x00ff for you hex freeks out there, heh
heh). After clicking okay, a brief message pops up, then dissappears
that says:

Exiting due to signal SIGSEGV
General Protection Fault at eip=000043c6
...(more register contents follow)...

One thing I notice, which may have nothing to do with it, is some of
the register listings look something like this:

cs: sel=043f base=83b4f000 limit=0009ffff

Looks like I may have something in the register that is greater than
the "limit" (or are those segment specifiers?...need to learn assembly,
eh)? There are about four registers (segments?) that display the same
kind of thing. Probably nothing, eh?
Anyway, when that disappears, it is replaced by the following:

Call frame traceback:
in function strcpy+14
prog1.c(26) in function main
in function __crt1_startup+174

I hope some of this made sense to someone. Anyway, is it something with
DJGPP, or perhaps RHIDE? Or is it just somehow non-portable code which
only DJGPP finds to be so? Thanks in advance.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

- Raw text -


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