473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

null pointer question???

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 );


--
Sent by nysfp from hotmail subpart from com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new
Jul 19 '05 #1
4 2353
"ny***@hotmail.com" <u5********@spawnkill.ip-mobilphone.net> wrote in
message news:l.*********************@[63.127.215.130]...
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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #2
ny***@hotmail.com wrote:
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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #3


"ny***@hotmail.com" wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #4


Karl Heinz Buchegger wrote:

"ny***@hotmail.com" wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dmitry D | last post by:
Hi, I'm new to C++ (started learning in the beginning of this summer), and I have the following question (sorry if it sounds stupid): In many code samples and source files, I see NULL expression...
10
by: DevarajA | last post by:
I've read that 0 is the 'null pointer constant', and assigning it to a pointer makes it a 'null pointer'. Is that true? And is the opposite true? (assigning a null pointer to an int sets the int to...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
15
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer...
51
by: muktipada | last post by:
Hello, As a C++ developer which one we should use for pointer assignment, NULL or 0. typedef DummyC DummyClass*; // in some header file. DummyC obj = NULL; if (obj == NULL) {
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.