www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - basic_reg_value::value_sz problem

reply "Diego Chanoux" <diego.chanoux libero.it> writes:
I tried to use the UNICODE sequence registry classes contained in WinSTL.

All works well except the fact that the basic_reg_value::value_sz ()
function return a dirty buffer if the registry value is empty. I debugged
and I realized a strange behavior about RegQueryValueExW () Windows API.
Sometimes, this API fills the buffer with only one NULL instead of two (in
UNICODE there must be two NULL characters to end a string) if the registry
value is empty.
The problem is that the basic_reg_value::value_sz () does not initialize the
buffer to be null terminated before to call the traits_type::reg_query_value
() so the buffer returned is dirty.

The workaround would be to put a buffer[0] = 0 line before the call to
traits_type::reg_query_value ()

To test this bug you can simply change the
STLSoft\test\winstl\reg_value_sequence_test.cpp file to use the UNICODE
classes, compile it, and create a key in the registry with some values of
type REG_SZ. You fill some values and you leave empty some others and you
should see the bug.
Oct 30 2003
next sibling parent "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> writes:
Deigo

Sorry, but I'm not feeling terribly intelligent this morning. (Mind on other
things ...) :)

Any chance you could send (or post) a code snippet showing the problem
and/or your proposed solution?

Cheers

Matthew

"Diego Chanoux" <diego.chanoux libero.it> wrote in message
news:bnremh$1fq6$1 digitaldaemon.com...
 I tried to use the UNICODE sequence registry classes contained in WinSTL.

 All works well except the fact that the basic_reg_value::value_sz ()
 function return a dirty buffer if the registry value is empty. I debugged
 and I realized a strange behavior about RegQueryValueExW () Windows API.
 Sometimes, this API fills the buffer with only one NULL instead of two (in
 UNICODE there must be two NULL characters to end a string) if the registry
 value is empty.
 The problem is that the basic_reg_value::value_sz () does not initialize

 buffer to be null terminated before to call the

 () so the buffer returned is dirty.

 The workaround would be to put a buffer[0] = 0 line before the call to
 traits_type::reg_query_value ()

 To test this bug you can simply change the
 STLSoft\test\winstl\reg_value_sequence_test.cpp file to use the UNICODE
 classes, compile it, and create a key in the registry with some values of
 type REG_SZ. You fill some values and you leave empty some others and you
 should see the bug.

Oct 30 2003
prev sibling parent reply "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> writes:
I've worked out the problem. It's not what you say, because a terminating
null character is appended. The problem is that I mistakenly terminate the
null at an index given by the data size, which in Unicode is twice the size
it should be. <blush>

I've fixed it now, and it'll appear in the next release.

If you want to patch it yourself, you just need to change the line

            buffer[data_size] = 0;

to

            buffer[data_size / sizeof(char_type)] = 0;


Thanks for spotting it

Matthew

"Diego Chanoux" <diego.chanoux libero.it> wrote in message
news:bnremh$1fq6$1 digitaldaemon.com...
 I tried to use the UNICODE sequence registry classes contained in WinSTL.

 All works well except the fact that the basic_reg_value::value_sz ()
 function return a dirty buffer if the registry value is empty. I debugged
 and I realized a strange behavior about RegQueryValueExW () Windows API.
 Sometimes, this API fills the buffer with only one NULL instead of two (in
 UNICODE there must be two NULL characters to end a string) if the registry
 value is empty.
 The problem is that the basic_reg_value::value_sz () does not initialize

 buffer to be null terminated before to call the

 () so the buffer returned is dirty.

 The workaround would be to put a buffer[0] = 0 line before the call to
 traits_type::reg_query_value ()

 To test this bug you can simply change the
 STLSoft\test\winstl\reg_value_sequence_test.cpp file to use the UNICODE
 classes, compile it, and create a key in the registry with some values of
 type REG_SZ. You fill some values and you leave empty some others and you
 should see the bug.

Oct 30 2003
parent reply "Diego Chanoux" <diego.chanoux libero.it> writes:
Thanks for your response. I have followed your suggestion and all is ok now.

Diego

"Matthew Wilson" <matthew-hat -stlsoft-dot.-org> wrote in message
news:bnsitk$152$1 digitaldaemon.com...
 I've worked out the problem. It's not what you say, because a terminating
 null character is appended. The problem is that I mistakenly terminate the
 null at an index given by the data size, which in Unicode is twice the

 it should be. <blush>

 I've fixed it now, and it'll appear in the next release.

 If you want to patch it yourself, you just need to change the line

             buffer[data_size] = 0;

 to

             buffer[data_size / sizeof(char_type)] = 0;


 Thanks for spotting it

 Matthew

 "Diego Chanoux" <diego.chanoux libero.it> wrote in message
 news:bnremh$1fq6$1 digitaldaemon.com...
 I tried to use the UNICODE sequence registry classes contained in


 All works well except the fact that the basic_reg_value::value_sz ()
 function return a dirty buffer if the registry value is empty. I


 and I realized a strange behavior about RegQueryValueExW () Windows API.
 Sometimes, this API fills the buffer with only one NULL instead of two


 UNICODE there must be two NULL characters to end a string) if the


 value is empty.
 The problem is that the basic_reg_value::value_sz () does not initialize

 buffer to be null terminated before to call the

 () so the buffer returned is dirty.

 The workaround would be to put a buffer[0] = 0 line before the call to
 traits_type::reg_query_value ()

 To test this bug you can simply change the
 STLSoft\test\winstl\reg_value_sequence_test.cpp file to use the UNICODE
 classes, compile it, and create a key in the registry with some values


 type REG_SZ. You fill some values and you leave empty some others and


 should see the bug.


Oct 31 2003
parent "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> writes:
Cool. :)

"Diego Chanoux" <diego.chanoux libero.it> wrote in message
news:bntc6l$1j2r$1 digitaldaemon.com...
 Thanks for your response. I have followed your suggestion and all is ok

 Diego

 "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> wrote in message
 news:bnsitk$152$1 digitaldaemon.com...
 I've worked out the problem. It's not what you say, because a


 null character is appended. The problem is that I mistakenly terminate


 null at an index given by the data size, which in Unicode is twice the

 it should be. <blush>

 I've fixed it now, and it'll appear in the next release.

 If you want to patch it yourself, you just need to change the line

             buffer[data_size] = 0;

 to

             buffer[data_size / sizeof(char_type)] = 0;


 Thanks for spotting it

 Matthew

 "Diego Chanoux" <diego.chanoux libero.it> wrote in message
 news:bnremh$1fq6$1 digitaldaemon.com...
 I tried to use the UNICODE sequence registry classes contained in


 All works well except the fact that the basic_reg_value::value_sz ()
 function return a dirty buffer if the registry value is empty. I


 and I realized a strange behavior about RegQueryValueExW () Windows



 Sometimes, this API fills the buffer with only one NULL instead of two


 UNICODE there must be two NULL characters to end a string) if the


 value is empty.
 The problem is that the basic_reg_value::value_sz () does not



 the
 buffer to be null terminated before to call the

 () so the buffer returned is dirty.

 The workaround would be to put a buffer[0] = 0 line before the call to
 traits_type::reg_query_value ()

 To test this bug you can simply change the
 STLSoft\test\winstl\reg_value_sequence_test.cpp file to use the



 classes, compile it, and create a key in the registry with some values


 type REG_SZ. You fill some values and you leave empty some others and


 should see the bug.



Oct 31 2003