Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About the null termination (UB 1.3.3)

 
Jari Timonen
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i've searched, tried and tried. I still can't get null termination right:

Choises:
char c = '\u0000'
byte b = 00000000;
String s = new String(byte[]{00000000}, "US-ASCII");

I write them back to file as byte-array. They just print out as "boxes" when i re-read them. (data is ok still, but null termination is someshow messed up)


Can somebody bend me a wire?
 
Jari Timonen
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allright, i've come to conclution, that i'm doing everything correctly. I checked with hex editor and indeed my null terminators are: 00 00 00 ..
But, the file contains 20 20 20 .. that is a space.

I'll go what the specs says:

null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.

 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jari Timonen wrote:Allright, i've come to conclution, that i'm doing everything correctly. I checked with hex editor and indeed my null terminators are: 00 00 00 ..
But, the file contains 20 20 20 .. that is a space.

I'll go what the specs says:

null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.


The spec explicitly says to end with null terminator. However, it also says to support the database file.. You must be able to handle records padded with white spaces...
I documented that the spec was contradictory, that other application were possibly using the database file and could be unable to handle another padding character.. I chose to use "blank space" to @null terminated@ my records
Another choice could be to replace spaces by null value as you modify the records..

I think the only wrong choice is not being able to handle spaces terminated records since that's how the database is by default.

Alex
 
Jari Timonen
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Belisle Turcot wrote:
The spec explicitly says to end with null terminator. However, it also says to support the database file.. You must be able to handle records padded with white spaces...
I documented that the spec was contradictory, that other application were possibly using the database file and could be unable to handle another padding character.. I chose to use "blank space" to @null terminated@ my records
Another choice could be to replace spaces by null value as you modify the records..

I think the only wrong choice is not being able to handle spaces terminated records since that's how the database is by default.

Alex



Handling the termination is just trivial issue, String.trim() makes the trick.

You've got point there. The other program might not know how to handle null terminations. I've got to think about it Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic