473,320 Members | 1,946 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,320 software developers and data experts.

How to treat unknown data...

I have a dilemma.

Currently, I may be passing standard text (strings of char) or binary of 1
to 'x' bytes long to a program for comparison with data previously written
to a file. The problem I'm having is I'm writing some routines which may
compare the data written on the disk to the some data being passed by the
programmer. And, the streams I'm passing may be shorter than the allowable
length limit (defined at runtime) but never longer. The problem I'm having
is that if I pass say, a string, the program I've written so far compares
'data' from programmer (less than or eq max possible length) to data on
disk- so the comparison currently compares the total possible size of the
string of bytes. What happens is that if I pass a standard string of char,
say "abcde" (with null terminator), my program compares "abcde\0[some
garbage]" to what ended up on disk- and of course the comparison fails,
because what may have been written to the disk is "abcde\0[some different
garbage]". What I'm trying to get my mind around is, is there any non-brute
force method of of guaranteeing the contents of the data- or scrubbing it
before writing to disk AND before recomparison so what the programmer
INTENDS to compare is what is actually being compared. The program as it is
MUST write all bytes of the allowable length. But it won't know WHAT it's
writing at runtime- only some fixed # of bytes of type 'void'. What I've
considered/considering thus far:

o Creating a meta table so the program knows at startup that it's comparing
strings, or binary, or both. (Don't like this- don't want the overhead)
o Simply demanding that the programmer clear the array of bytes so that it
contains NULLS for the entire length before writing to disk or comparing.
(makes more work for the programmer using the class/functions- and leads to
possible error if programmer is sloppy and doesn't clear memory).
o Having the programmer pass a secondary argument telling the class/function
to compare only 'x' bytes of the string being passed. Ie:
foo(bytestring,strlen(bytestring)); Where 'foo' performs:

xxx foo(void* bytes,int nlength)
{
return Compare(bytes,bytesreadfromdisk,nlength);
}

I'm not pleased with any of these methods, and am looking for something more
elegant. I've investigated templates (of which I'm very inexperienced), but
after reading a tutorial, I didn't find it to be aiming towards what I
really wanted.

Again, a string of bytes can be up to a given length (previously defined and
program becomes aware at runtime) and the string can contain readable text,
binary, or both- intermixed. The general FORMAT of the data will not change
at runtime. Ie, a 25 byte string may contain 10 of string, 4 of binary, 7
of string, and 3 of binary- much like an old flat file database system
would. Any ideas appreciated. And I'm happy to provide clarifications.

paul
Jul 22 '05 #1
2 1933
Why do you not require that all elements of the buffer are initialized
to 0?
Then you can always compare byte by byte.

Stephan Brönnimann
br****@osb-systems.com
http://www.osb-systems.com
Open source rating and billing engine for communication networks.

Jul 22 '05 #2
In essence, I am requiring that they be initialized to 0, but I don't want
to create unnecessary overhead for the programmer using my class- or create
a burdensome process where steps might be forgotten. My initial vision was
that I would provide member functions which would add data in one step, and
compare/find it in one step as thus:

AddData(data);
[...]
FindData(data);

The 'FindData(...)' member funciton reads data from the disk and basically
does a memcmp() on it. But because it's a generic class going to a
predefined file (fixed length elements) it will compare the entire length of
the data element, even if the data being passed by the programmer contains:
"paul\0".

I can certainly create a 'scrubber function' which might work like thus:

BuildData(data); //scrubs out data putting in NULL then puts programmer
data into buffer
AddData(data); //Adds the data
[...]
BuildData(data); //ditto
FindData(data);

While this approach will work, if the programmer forgets the 'BuildData'
function before any call to write or compare data, the compare will fail, or
the 'Add' will write 'unexpected' trailing garbage at the end of the data
buffer (which may or may not be null terminated). This introduces the
possibility of more bugs.

Paul
"Stephan Brönnimann" <br****@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Why do you not require that all elements of the buffer are initialized
to 0?
Then you can always compare byte by byte.

Stephan Brönnimann
br****@osb-systems.com
http://www.osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #3

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

Similar topics

3
by: Marcus | last post by:
I'm running into a situation that has me adding a value of "Unknown" to a reference table. I am being pulled between two trains of thought, and was curious to get other's input on in. I give an...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
11
by: Jeevan | last post by:
Hi, I have some data which I am getting from a socket. I am currently storing the data in an array (so that future reading of the data will be fast as it will be in RAM instead of hard disk)....
6
by: quilkin | last post by:
I am getting a System.Data.SqlClient.SqlException with a message string of 'Unknown Error'. Happens occasionally when creating a "new SqlCommand(...)" while the same command works perfectly happily...
9
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
1
by: TARUN | last post by:
Hello All, I am facing problem regarding Atlas. I have install the AtlasSetup.msi in my .NET framework 2.0, and i open the new Atlas Website...... Let me first explain the my senario, I...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.