Paul Vermeer
2015-Sep-01 08:26 UTC
[Nut-upsuser] functional bug in code /clients/nutclient.cpp
Hi nut users, (this is a re-send from the correct account) With pleasure, I have been using the code provided. Managed to get all working properly, except for the nutclient lib in C. Both functions stringset_to_strarr and stringvector_to_strarr have a similar bug in play. Although trivial in code, the coded function does not operate as intended. The pointer increment is missing (see added line marked yellow below [pstr++;]), which results in the same element being updated over and over again, and then only leaving the last element of the list in the array. Kind regards, Paul Vermeer. (also I could not find out how to 'install' the include files properly using the autogen.sh / .configure and make and make install scripts. - had to copy them manually as I'm no expert in make scripts) static strarr stringset_to_strarr(const std::set<std::string>& strset) { strarr arr = strarr_alloc(strset.size()); strarr pstr = arr; for(std::set<std::string>::const_iterator it=strset.begin(); it!=strset.end(); ++it) { *pstr = xstrdup(it->c_str()); pstr++; } return arr; } static strarr stringvector_to_strarr(const std::vector<std::string>& strset) { strarr arr = strarr_alloc(strset.size()); strarr pstr = arr; for(std::vector<std::string>::const_iterator it=strset.begin(); it!=strset.end(); ++it) { *pstr = xstrdup(it->c_str()); pstr++ } return arr; } -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20150901/7e1484bf/attachment.html>
Charles Lepple
2015-Sep-03 13:11 UTC
[Nut-upsuser] functional bug in code /clients/nutclient.cpp
On Sep 1, 2015, at 4:26 AM, Paul Vermeer <paul at elspaulnz.com> wrote:> > Hi nut users, (this is a re-send from the correct account) > > With pleasure, I have been using the code provided. Managed to get all working properly, except for the nutclient lib in C.As you have noticed, nutclient has a few rough edges. The original upsclient library has had a lot more testing, although it is written in straight C. Be careful with some of the other nutclient wrappers. There are try/catch blocks that mask exceptions.> Both functions stringset_to_strarr and stringvector_to_strarr have a similar bug in play. Although trivial in code, the coded function does not operate as intended. > The pointer increment is missing (see added line marked yellow below [pstr++;]), which results in the same element being updated over and over again, and then only leaving the last element of the list in the array.I created an issue on Github to track this: https://github.com/networkupstools/nut/issues/232 <https://github.com/networkupstools/nut/issues/232> Should be easy to fix, but we also need to add some unit tests to keep this sort of thing from cropping up again.> Kind regards, Paul Vermeer. > > > (also I could not find out how to ?install? the include files properly using the autogen.sh / .configure and make and make install scripts. ? had to copy them manually as I?m no expert in make scripts)I was going to suggest that we should compare your settings to what Linux distributions do to package nutclient, but neither Debian nor Ubuntu has packaged it (only libupsclient*), and I haven't looked at other distributions yet. (This might be a sign...) Which options are you passing to ./configure? -- Charles Lepple clepple at gmail -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20150903/e50434e8/attachment.html>
Charles Lepple
2015-Sep-04 01:40 UTC
[Nut-upsuser] functional bug in code /clients/nutclient.cpp
On Sep 3, 2015, at 9:11 AM, Charles Lepple <clepple at gmail.com> wrote:> > Which options are you passing to ./configure?Just noticed that this defaults to "no": ./configure --help [...] --with-dev build and install the development files (no) -- Charles Lepple clepple at gmail -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20150903/78272981/attachment-0001.html>