Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 30, 2003 basic_reg_value::value_sz problem | ||||
---|---|---|---|---|
| ||||
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. |
October 30, 2003 Re: basic_reg_value::value_sz problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Diego Chanoux | 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 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. > > |
October 31, 2003 Re: basic_reg_value::value_sz problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Diego Chanoux | 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 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. > > |
October 31, 2003 Re: basic_reg_value::value_sz problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | 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 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 > 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. > > > > > > |
October 31, 2003 Re: basic_reg_value::value_sz problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Diego Chanoux | 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 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 > 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 > > 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. > > > > > > > > > > > > |
Copyright © 1999-2021 by the D Language Foundation