• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About the null termination (UB 1.3.3)

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic