简体   繁体   中英

Arguments corrupted on passing in to function?

I'm seeing something that's got me stumped. Maybe you folks can advise.

What appears to be a valid arguments are getting corrupted when passed to a different function.

Here is my setup:

  • LibA.a
  • LibB.a
  • SampleApp
  • MyApp.c

The bad function call is going from LibA in to LibB.

LibA, LibB and SampleApp have all been pre-complied (thankfully in debug mode) by an older version of Sun Studio on Solaris x86/64. SampleApp uses both LibA and LibB and runs just fine on my system.

MyApp uses both LibA and LibB in a manner similar to SampleApp. Yet, MyApp crashes due to this pointer corruption.

// File scoped string declared
static const char myString[] = "SomeText"

// The function call looks like  
libAfunc(myString, myIntVar)

// The called function prototype is like 
int libAfunc(const char* strArg, int intArg)

When single stepping the code, I see the pointer in the caller ( myString ) being valid and being passed as a parameter. In the callee, the address in the passed-in parameter pointer ( strArg ) is simply wrong. In fact, all the parameters are actually wrong after passing in.

Note: The caller is in the pre-compiled LibA and the callee is in the pre-compiled LibB. I'm never even touching that code since it's all pre-compiled. Further, the code itself is probobly correct since SampleApp uses those functions, and runs fine. (Although the call sequence could be slightly different...)

I'm thinking that my error is in the linking stage, but I'm not sure what it could be.

Any ideas?

Thank you

Can you compile SimpleApp with your compiler? Does it still work?

I'm not familiar with your particular platform, but there was a time with some compilers where pointers could be different sizes depending upon the compiler options used.

If your compiler was producing (say) 64 bit pointers and the libs were using 32 bit pointers then your symptoms make sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM