0

decNumber.h:

typedef struct {
int32_t digits;      /* Count of digits in the coefficient; >0    */
int32_t exponent;    /* Unadjusted exponent, unbiased, in         */
                     /* range: -1999999997 through 999999999      */
uint8_t bits;        /* Indicator bits (see above)                */
                     /* Coefficient, from least significant unit  */
decNumberUnit lsu[DECNUMUNITS]; // decNumberUnit is int16_t and DECNUMUNITS is 1
} decNumber;

Test.cpp:

decNumber a,b,c;

When I print the addresses of a,b and c, this is what I get:

a:0x7fff0d7a9858 to 0x7fff0d7a9864

b:0x7fff0d7a9864 to 0x7fff0d7a9870

c:0x7fff0d7a987c to 0x7fff0d7a9888

Is the byte overlap of 0x7fff0d7a9864 between a and b valid? This program eventually runs into a segmentation fault. Why?

Any help is greatly appreciated!

rsy
  • 192
  • 2
  • 10
  • 1
    How do you "print the addresses"? ([Maybe related](http://stackoverflow.com/q/9963401/596781)) – Kerrek SB Mar 12 '15 at 18:20
  • 1
    Is there really a byte overlap? Or are you printing something like `&a + 1` or `(char*)&a + sizeof(a)`, which will give the address past the end of `a`, which can be used by another object? – Mike Seymour Mar 12 '15 at 18:25
  • Thanks for your comments Mike. I eventually figured out there was something similar being done in the decnumber library where the struct pointers were being incremented in a for loop. The reason we were running into a seg fault was because we did not allocate enough space (specific values need to be set to have the right DECNUMUNITS) in our code for the decNumber struct. – rsy Mar 16 '15 at 21:28

1 Answers1

1

Is the byte overlap of 0x7fff0d7a9864 between a and b valid?

There is no byte overlap. For example, 0 to 5 means [0, 1, 2, 3, 4] and 5 to 10 means [5, 6, 7, 8, 9].

This program eventually runs into a segmentation fault. Why?

Impossible. The program in the question is incomplete and does not compile. It can not cause a segmentation fault, because there is no program that can run.

orlp
  • 112,504
  • 36
  • 218
  • 315