[Nut-upsuser] functional bug in code /clients/nutclient.cpp

Paul Vermeer paul at elspaulnz.com
Tue Sep 1 08:26:39 UTC 2015


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>


More information about the Nut-upsuser mailing list