null pointer question???

N

nysfp

unsigned char *Buf;
Buf = new unsigned char[100];
unsigned long sz = 100 * sizeof(unsigned char);
Read(Buf,&sz);
Occassional app crash at Read(Buf,&sz) call.
maybe empty data, null Buf??.
what's best way?.

Lib:
Read ( unsigned char * Buf ,
unsigned long * BufSize );
 
J

Jakob Bieling

unsigned char *Buf;
Buf = new unsigned char[100];
unsigned long sz = 100 * sizeof(unsigned char);
Read(Buf,&sz);
Occassional app crash at Read(Buf,&sz) call.
maybe empty data, null Buf??.

Maybe, yes. Maybe the error lies elsewhere. The point is that the error
obviously occurs inside 'Read' and you have not shown anything about that
function. If it is function of a third-party library, you should try asking
the developers or a forum dedicated to this library. Otherwise, please show
the relevant code of that function.

hth
 
K

Kevin Goodsell

unsigned char *Buf;
Buf = new unsigned char[100];
unsigned long sz = 100 * sizeof(unsigned char);

sizeof(unsigned char) is a fancy way of writing 1.
Read(Buf,&sz);
Occassional app crash at Read(Buf,&sz) call.
maybe empty data, null Buf??.
what's best way?.

Lib:
Read ( unsigned char * Buf ,
unsigned long * BufSize );

Why is this a pointer? Are you sure the library is not modifying your
size, causing it to be incorrect when you call this function later?

-Kevin
 
K

Karl Heinz Buchegger

unsigned char *Buf;
Buf = new unsigned char[100];
unsigned long sz = 100 * sizeof(unsigned char);
Read(Buf,&sz);
Occassional app crash at Read(Buf,&sz) call.
maybe empty data, null Buf??.
what's best way?.

Lib:
Read ( unsigned char * Buf ,
unsigned long * BufSize );

I think you are using your library the wrong way.
An interface like the above is usually feed like this:

unsigned char *Buf;
unsigned long BuffSize;

Buf = new unsigned char [ 100 ];
BuffSize = 100;

Read( Buf, &BuffSize );

and read will modify BuffSize to the number of unsigned chars
it put into Buf. But it wants to know in the beginning how large
that buffer actually is, in order to avoid what you have seen:
accessing the array out of bounds and thus end up in an access
violation.

Consult your documentation, if that's what Read does.
 
K

Karl Heinz Buchegger

Karl said:
unsigned char *Buf;
Buf = new unsigned char[100];
unsigned long sz = 100 * sizeof(unsigned char);
Read(Buf,&sz);
Occassional app crash at Read(Buf,&sz) call.
maybe empty data, null Buf??.
what's best way?.

Lib:
Read ( unsigned char * Buf ,
unsigned long * BufSize );

I think you are using your library the wrong way.
An interface like the above is usually feed like this:

unsigned char *Buf;
unsigned long BuffSize;

Buf = new unsigned char [ 100 ];
BuffSize = 100;

Read( Buf, &BuffSize );

Ooops. Sorry. At reread I notices that thats exactly
what you are doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top