Segmentation violation - weird!

Segmentation violation - weird!

Post by Jeff A. Fitzgeral » Thu, 11 Feb 1999 04:00:00



Hi, all

In a C program on a Data General intel-based system, I'm having a very
strange problem.  If anyone has any thoughts at all, I'd be most
appreciative.  Here's a code snipet:

        char    bufftemp[256];
        int     release;

        release = 260;

        sprintf(bufftemp, "\376%d", release);

It compiles fine, but produces a segmentation violation at runtime......
If I change the "\376" to "\100" the problem goes away......  I'm trying to
include the \376 because I'm passing the final string to a database that
recognizes that character as a field mark.

Comments or ideas?

Thanks in advance!

Jeff Fitzgerald


 
 
 

Segmentation violation - weird!

Post by Aaron Cra » Thu, 11 Feb 1999 04:00:00




Quote:>       char    bufftemp[256];
>       int     release;

>       release = 260;

>       sprintf(bufftemp, "\376%d", release);

> It compiles fine, but produces a segmentation violation at runtime.  If I
> change the "\376" to "\100" the problem goes away.  I'm trying to include
> the \376 because I'm passing the final string to a database that
> recognizes that character as a field mark.

Puzzling.  Is that genuinely what you're compiling?  I tried this, as is:

    #include <stdio.h>
    int main (void) {
        char buf[256];
        sprintf (buf, "\376%d", 260);
        puts (buf);
        return 0;
    }

It works fine, printing a lower-case thorn character (0376 in Latin-1)
followed by 260, and then a newline.  If that doesn't work, then I'd guess
that your sprintf has a bug; complain to your vendor.

--


 
 
 

Segmentation violation - weird!

Post by Victor Wagn » Fri, 12 Feb 1999 04:00:00



: Hi, all

: In a C program on a Data General intel-based system, I'm having a very
: strange problem.  If anyone has any thoughts at all, I'd be most
: appreciative.  Here's a code snipet:

:       char    bufftemp[256];
:       int     release;

:       release = 260;
:      
:       sprintf(bufftemp, "\376%d", release);

: It compiles fine, but produces a segmentation violation at runtime......
: If I change the "\376" to "\100" the problem goes away......  I'm trying to
: include the \376 because I'm passing the final string to a database that
: recognizes that character as a field mark.

It might be that you cannot pass values above 127 such way. Strange
although...

Try declare bufftemp as

unsigned char

Or just type character as is, for example hitting
^V254 in vi insert mode. On my system 254 is pretty valid char (cyrillic
locale)

--
--------------------------------------------------------
I have tin news and pine mail...

 
 
 

Segmentation violation - weird!

Post by Jeff A. Fitzgeral » Fri, 12 Feb 1999 04:00:00


Hi, all

    An update -- solved my problem by declaring bufftemp as unsigned char
instead of just char....

    Very strange!

Thanks for the help

Jeff Fitzgerald