How to check pointer for invalid value under dpmi? 
Author Message
 How to check pointer for invalid value under dpmi?

Hi

Need some help here, can't figure this puzzle out...

In my program, I have a variable, (pointer) to a string,  the pointer
is getting trashed somehow, and causes a 216 error when I try to
access it.

How can I tell if this pointer is pointing to an address in my space?
Or in other words, how can I tell if it is valid or not?

Thanks for any help!

Ray



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?



Quote:

>In my program, I have a variable, (pointer) to a string,  the pointer
>is getting trashed somehow, and causes a 216 error when I try to
>access it.

>How can I tell if this pointer is pointing to an address in my space?
>Or in other words, how can I tell if it is valid or not?

If your pointer is getting trashed, something else in your program must
be corrupting it. Try using the de{*filter*} and set Breakpoints/Changed
Memory Global. That should find where the corruption is occurring.

--

Never curse the Crocodile's mother before crossing the river



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?

Quote:

> In my program, I have a variable, (pointer) to a string,  the pointer
> is getting trashed somehow, and causes a 216 error when I try to
> access it.

> How can I tell if this pointer is pointing to an address in my space?
> Or in other words, how can I tell if it is valid or not?

Hi,

The standard heap routines does not return invalid pointers. If your
variables get "trashed", you have to correct the code which does this,
instead of checking the pointers!

Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?

Thanks for the replies, although they don't help much....

The pointer is in a dynamic array created in a Turbopower product
called Tpro.  So it is not exactly "my code" :)

How do I set a breakpoint for when an area changes when I don't even
know what the area is ?  That reads goofy, but I don't know how else
to explain it..

Ray



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?

Quote:

> Thanks for the replies, although they don't help much....

Hi!

Well, to check a pointer, you have to check the "segment" and the
"offset" parts, too. In protected mode it's more complicated than real
mode. The segment selector value does not reflect the linear address.
You can try checking the selector's base address and the segment limit
(GetSelectorBase() & GetSelectorLimit() as I remember (WinAPI unit for
DPMI, too)). If returns invalid address (0?), then you have an invalid
selector which will cause a protection fault. The "offset" must be
between 0 and the {*filter*}t limit value.

I have another problem: a pointer may contain a valid _code_ selector.
This seems to be valid, but writing to a code segment is also a
protection fault! And you may have a pointer which is absolutely valid,
but pointing to invalid data in the heap. I tell you again: trashing
memory variables isn't a normal program behaviour!

Quote:
> How do I set a breakpoint for when an area changes when I don't even
> know what the area is ?  That reads goofy, but I don't know how else
> to explain it..

In Turbo De{*filter*}:
Select the Breakpoints menu. You'll find a "Changed memory" option. You
can use this, but it will run very slowly: the de{*filter*} evaluates it
after executing every single statement.

Regards
Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?



Quote:
>Thanks for the replies, although they don't help much....

>The pointer is in a dynamic array created in a Turbopower product
>called Tpro.  So it is not exactly "my code" :)

Just a small point but have you made sure you passed the correct info to
initialise the dynamic array?

Quote:
>How do I set a breakpoint for when an area changes when I don't even
>know what the area is ?  That reads goofy, but I don't know how else
>to explain it..

Re-compile the relevant bits of TPRO using the full debugging options
{$D+} {$L+} {$Y+}, look inthe source code to get the name of the pointer
variable and use a fully qualified {unit/object instance/name} variable
name.

As it's a Turbopower product, you may want to look on their website
<URL:http://www.tpower.com> in case it is a known problem and there is a
fix. They will be interested if you have a genuine bug.

I don't have TPRO (I use a collection of 35 units I wrote myself) so
can't suggest you email the problem code when I could have a look at it.

--

Never curse the Crocodile's mother before crossing the river



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?


Quote:

>Hi

>Need some help here, can't figure this puzzle out...

>In my program, I have a variable, (pointer) to a string,  the pointer
>is getting trashed somehow, and causes a 216 error when I try to
>access it.

>How can I tell if this pointer is pointing to an address in my space?
>Or in other words, how can I tell if it is valid or not?

If you have broken leg, do you really want to use morphine to kill the
pain or fix the leg?

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?



Quote:


> >Hi

> >Need some help here, can't figure this puzzle out...

> >In my program, I have a variable, (pointer) to a string,  the pointer
> >is getting trashed somehow, and causes a 216 error when I try to
> >access it.

> >How can I tell if this pointer is pointing to an address in my space?
> >Or in other words, how can I tell if it is valid or not?

> If you have broken leg, do you really want to use morphine to kill the
> pain or fix the leg?

Maybe he wants to use morphine to be able to examine the leg so he can fix
it.

Do you never add some fatal-error-statments to your code, things that should
never happen? They can catch a crash in the root so you can find and fix the
bug.

Quote:
> Osmo

--
Arsne von Wyss

+---------------------------------------------------------------------------+
| Pascal, Delphi & Personal stuff: http://www.beaulieu-software.ch/avonwyss |
|   Swiss IOI'97 homepage: http://www.beaulieu-software.ch/avonwyss/ioi97   |
|  Prog. Contest Problems Archive: http://www.beaulieu-software.ch/contest  |
+---------------------------------------------------------------------------+
         |  "Is that your C program listing or is it line noise?"  |
         +---------------------------------------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check pointer for invalid value under dpmi?

Quote:



> > >Hi

> > >Need some help here, can't figure this puzzle out...
> > >In my program, I have a variable, (pointer) to a string,  the pointer
> > >is getting trashed somehow, and causes a 216 error when I try to
> > >access it.> > >
> > >How can I tell if this pointer is pointing to an address in my space?
> > >Or in other words, how can I tell if it is valid or not?

> > If you have broken leg, do you really want to use morphine to kill the
> > pain or fix the leg?

> Maybe he wants to use morphine to be able to examine the leg so he can fix
> it.

> Do you never add some fatal-error-statments to your code, things that should
> never happen? They can catch a crash in the root so you can find and fix the
> bug.

> > Osmo

> Arsne von Wyss

Hmmm, in fact I sometimes happen to make the (always) same mistake:
I allocate memory for say a byte-array
(TYPE TMYARRAY = ARRAY [1..100] of BYTE) via

        NEW(MYARRAY);

and then want to clear it; perhaps there are better ways to do it but I
do it like this:

        FILLCHAR(MYARRAY^, sizeof(TMYARRAY),0);

If you miss to enter the "^ you do write the zeros starting at the
address of MYARRAY, I guess ... and after the 4 bytes for its pointer
you destroy some other data since the data of MYARRAY is to be found at
the address contained at the address of the variable of MYARRAY ... gee,
I suppose that did the trick to confuse everybody. If I got it wrong,
please correct it. Anyway, fact is that this causes {*filter*} GP-errors and
their causes is not easily found.

Hope this helps!?

Bernd Heutling



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Mouse driver check in DPMI protected mode BP

2. ORA-1722 Invalid number when inserting a value

3. Invalid pointer operation

4. Invalid Pointer Operation after FPC 1.00 installation and an Ansistring problem

5. dipose [Invalid Pointer operation]

6. Invalid pointer operation???!!!

7. Invalid Value for Field "Date1"

8. Invalid Pointer problem

9. Invalid numeric value in a TDBEdit

10. Overriding Type Checking for Pointers

11. Checking for bad heap-allocation and loose pointers

12. validity checks and default values (paradox tables)

 

 
Powered by phpBB® Forum Software