[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Puzzle: E2BIG from spawnlp.

Posted on 2006-04-07
12
Medium Priority
?
328 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:PaulCaswell
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 4

Expert Comment

by:uniques
ID: 16400388
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
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16400644
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
 
LVL 22

Expert Comment

by:grg99
ID: 16400695
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:KurtVon
ID: 16400809
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
 
LVL 11

Assisted Solution

by:KurtVon
KurtVon earned 200 total points
ID: 16401966
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
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16402883
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
 
LVL 14

Accepted Solution

by:
cwwkie earned 300 total points
ID: 16403974
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
 
LVL 11

Expert Comment

by:KurtVon
ID: 16404116
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
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16404265
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
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16404300
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
 
LVL 14

Expert Comment

by:cwwkie
ID: 16404436
> 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
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16404537
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question