• C

Puzzle: E2BIG from spawnlp.

All,

I just cracked a subtle bug! This was the situation:

This product runs correctly on a 16bit HHT (Hand Held Terminal).

I was forced to change from 'Medium Memory Model' to Large Memory Model and started getting error 7 (E2BIG: Argument list exceeds 1024 bytes) returned from:

            err = _spawnlp( P_WAIT, "B:TSCS.EXE", "TSCS", NULL);

What was the bug and how did I fix it?

Paul
LVL 16
PaulCaswellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uniquesCommented:
Does it have something to do with the medium model using near pointers for data and large memory model using far pointers for it? Did you have to maybe typecast "B:TSCS.EXE" and "TSCS" as far pointers?
0
PaulCaswellAuthor Commented:
The change of the memory model was the trigger for the problem coming to light but the strings are valid. No type casting was required.

Keep thinking! :-)

Paul
0
grg99Commented:
BTW that should probably be B:\\TSCS.EXE   unless you're really sure of the directory you're in.

did the environment get too big to make a copy of it and spawn another program?

or had you done something earlier to break the environment copy so it looked really huge?



0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

KurtVonCommented:
Well, considering the only memory model-related issue that should have changed, and the error you got, I'd assume it was an issue with the NULL.  I don't actually see the problem, but I'm guessing it was solved by replacing the NULL with an explicit 0.

Now, if the memory model was upgraded but for some reason you are using the old constants I suppose they could have typecast the NULL to a short pointer, but somehow that doesn't sound right.  Even on a  big endian system I would have needed to leave garbage in the first part of the parameter so that the "two zeros in a row" technique of detecting the end of the parameter list failed.

If so, I'm surprised that (a) the explicit typecast didn't throw a compiler warning anyway, and (b) the compiler would allow garbage bytes in the implict typecast back into whatever pointer type the function was expecting.

Hmm, maybe the NULL was getting cast into a pointer with an explicit DS value?
0
KurtVonCommented:
Hah, that is it.  Found this by assuming the explicit DS value answer was correct.  The correct solution is probably to get a new header file that defines NULL for the large memory model.

To quote "If you're in the medium memory model, the implicit casting of (void __near*)NULL to a __far* appends the data segment register to it, so the routine you're passing it to gets something which isn't (void __far*)NULL."
0
PaulCaswellAuthor Commented:
KurtVon,

You are so close! But not quite there! There is an assumption you are making that is wrong.

I will hold back on hints for a bit so others get a chance but you are looking in the right place.

Greg,

This is a 16bit handheld device. No subdirs, 3 ram drives (A: B: and D: believe it or not). Wrong track.

Paul
0
cwwkieCommented:
the only thing I can think of is that NULL is defined as 0, and sizeof(int)!=sizeof(void *) in the large memory model.
But that would mean the solution in the second post of KurtVon is correct.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KurtVonCommented:
Yeah, that's what got me too.  If NULL was defined as just 0, it should have been implicitly cast to 32 bits as a void* when put in the parameter list.  That would mean someone had to explicitly #define NULL as (int)0 (or (short)0) which isn't just a bad idea -- it's aggressively stupid.

If it isn't a near pointer NULL, I can't imagine what explicit typecast someone could screw it up with.

The real puzzle here, I guess, is "when is a NULL not a NULL?"

Is my false assumption that the processor uses a segment architecture?  If so, then I'm a bit stuck on what other differences there would be in the medium vs. large memory models.
0
PaulCaswellAuthor Commented:
Hi KurtVon,

>>If NULL was defined as just 0, it should have been implicitly cast to 32 bits as a void*
Nearly there! Now look at the prototype for spawnlp! :-)

Paul
0
PaulCaswellAuthor Commented:
Hi cwwkie,

>>But that would mean the solution in the second post of KurtVon is correct.
Perhaps I'm not reading it correctly but, again, take a peek at the spawnlp prototype and all will become clear.

Paul
0
cwwkieCommented:
> take a peek at the spawnlp prototype
there are dots, so there is no type conversion, meaning an int will stay an int. But that means if you call it with (void __far*)NULL, it should work.
0
PaulCaswellAuthor Commented:
Hi cwwkie,

Indeed it should! But if an incompetent used the old #define NULL (0) trick it doesnt! :-)

Good work guys! That'll should teach us all NEVER to use this form of NULL.

Looks like a tean effort! I'll split. Thanks people!

Paul
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.