c++.stlsoft - basic_reg_value::value_sz problem
- Diego Chanoux (17/17) Oct 30 2003 I tried to use the UNICODE sequence registry classes contained in WinSTL...
- Matthew Wilson (11/28) Oct 30 2003 Deigo
- Matthew Wilson (15/32) Oct 30 2003 I've worked out the problem. It's not what you say, because a terminatin...
- Diego Chanoux (11/48) Oct 31 2003 Thanks for your response. I have followed your suggestion and all is ok ...
- Matthew Wilson (9/68) Oct 31 2003 Cool. :)
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
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 initializethebuffer to be null terminated before to call thetraits_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
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 initializethebuffer to be null terminated before to call thetraits_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
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 thesizeit 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...WinSTL.I tried to use the UNICODE sequence registry classes contained indebuggedAll works well except the fact that the basic_reg_value::value_sz () function return a dirty buffer if the registry value is empty. I(inand I realized a strange behavior about RegQueryValueExW () Windows API. Sometimes, this API fills the buffer with only one NULL instead of tworegistryUNICODE there must be two NULL characters to end a string) if theofvalue is empty. The problem is that the basic_reg_value::value_sz () does not initializethebuffer to be null terminated before to call thetraits_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 valuesyoutype REG_SZ. You fill some values and you leave empty some others andshould see the bug.
Oct 31 2003
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 oknow.Diego "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> wrote in message news:bnsitk$152$1 digitaldaemon.com...terminatingI've worked out the problem. It's not what you say, because athenull character is appended. The problem is that I mistakenly terminateAPI.null at an index given by the data size, which in Unicode is twice thesizeit 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...WinSTL.I tried to use the UNICODE sequence registry classes contained indebuggedAll works well except the fact that the basic_reg_value::value_sz () function return a dirty buffer if the registry value is empty. Iand I realized a strange behavior about RegQueryValueExW () Windowsinitialize(inSometimes, this API fills the buffer with only one NULL instead of tworegistryUNICODE there must be two NULL characters to end a string) if thevalue is empty. The problem is that the basic_reg_value::value_sz () does notUNICODEthebuffer to be null terminated before to call thetraits_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 theofclasses, compile it, and create a key in the registry with some valuesyoutype REG_SZ. You fill some values and you leave empty some others andshould see the bug.
Oct 31 2003