From 1b6a214154325f6f6f2ce332e1ad31614ed482f3 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sat, 8 Aug 2020 19:13:53 -0400 Subject: [PATCH 1/3] WIP: Fixed various warnings and errors identified by cppcheck Specifically: arrayIndexThenCheck,drivers/nutdrv_qx_voltronic-qs-hex.c:222,style,Array index 'i' is used before limits check. arrayIndexThenCheck,drivers/oneac.c:176,style,Array index 'i' is used before limits check. clarifyCalculation,drivers/belkinunv.c:1063,style,Clarify calculation precedence for '&' and '?'. clarifyCalculation,drivers/belkinunv.c:922,style,Clarify calculation precedence for '&' and '?'. clarifyCalculation,drivers/powercom.c:677,style,Clarify calculation precedence for '&' and '?'. clarifyCalculation,drivers/powercom.c:732,style,Clarify calculation precedence for '&' and '?'. clarifyCondition,drivers/asem.c:248,style,Boolean result is used in bitwise operation. Clarify expression with parentheses. duplicateConditionalAssign,drivers/solis.c:725,style,The statement 'if (DaysOnWeek!=DaysOffWeek) DaysOnWeek=DaysOffWeek' is logically equivalent to 'DaysOnWeek=DaysOffWeek'. duplicateExpression,clients/cgilib.c:49,style,Same expression on both sides of '||'. duplicateExpression,drivers/nutdrv_qx_voltronic.c:270,style,Same expression on both sides of '||'. duplicateExpression,drivers/nutdrv_qx_voltronic.c:303,style,Same expression on both sides of '||'. duplicateExpression,drivers/nutdrv_qx_voltronic.c:397,style,Same expression on both sides of '||'. identicalInnerCondition,drivers/tripplite_usb.c:579,warning,Identical inner 'if' condition is always true. incorrectLogicOperator,drivers/dstate.c:1170,warning,Logical conjunction always evaluates to false: c2 && !c2. incorrectLogicOperator,drivers/rhino.c:190,warning,Logical disjunction always evaluates to true: BattVoltage > 129 || BattVoltage < 144. incorrectStringBooleanError,drivers/mge-utalk.c:899,warning,Conversion of string literal "\r\n" to bool always evaluates to true. invalidPrintfArgType_sint,clients/upsset.c:393,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. invalidPrintfArgType_sint,clients/upsset.c:676,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. invalidPrintfArgType_sint,drivers/isbmex.c:178,portability,%d in format string (no. 1) requires 'int' but the argument type is 'ssize_t {aka signed long}'. invalidPrintfArgType_sint,drivers/tripplitesu.c:435,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. knownConditionTrueFalse,clients/upsmon.c:919,style,Condition 'un' is always true knownConditionTrueFalse,drivers/gamatronic.c:111,style,Condition 'ret>=0' is always true knownConditionTrueFalse,drivers/powercom.c:696,style,Condition 'battval>bat0' is always true knownConditionTrueFalse,drivers/solis.c:485,style,Condition 'AppPower==0' is always false knownConditionTrueFalse,tools/nut-scanner/scan_nut.c:180,style,Condition 'numa>=3' is always true memleak,clients/upsset.c:664,error,Memory leak: val nullPointerRedundantCheck,drivers/snmp-ups.c:1554,warning,Either the condition 'info_template==NULL' is redundant or there is possible null pointer dereference: info_template. pointerLessThanZero,drivers/nut-libfreeipmi.c:864,style,A pointer can not be negative so it is either pointless or an error to check if it is. pointerLessThanZero,drivers/nut-libfreeipmi.c:884,style,A pointer can not be negative so it is either pointless or an error to check if it is. postfixOperator,clients/nutclient.cpp:896,performance,Prefer prefix ++/-- operators for non-primitive types. redundantInitialization,drivers/al175.c:548,style,Redundant initialization for 'reply'. The initialized value is overwritten before it is read. uninitMemberVar,clients/nutclient.cpp:504,warning,Member variable 'TcpClient::_timeout' is not initialized in the constructor. uninitMemberVar,clients/nutclient.cpp:513,warning,Member variable 'TcpClient::_timeout' is not initialized in the constructor. uninitvar,server/netssl.c:546,error,Uninitialized variable: ret unsignedLessThanZero,drivers/apcsmart-old.c:928,style,Checking if unsigned expression 'sdtype' is less than zero. unsignedPositive,drivers/bcmxcp.c:785,style,Unsigned expression 'commandByte' can't be negative so it is unnecessary to test it. uselessAssignmentPtrArg,drivers/riello_ser.c:105,warning,Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? --- clients/cgilib.c | 2 +- clients/nutclient.cpp | 4 +++- clients/upsmon.c | 5 +---- clients/upsset.c | 5 +++-- drivers/al175.c | 2 +- drivers/apcsmart-old.c | 2 +- drivers/asem.c | 2 +- drivers/bcmxcp.c | 2 +- drivers/belkinunv.c | 4 ++-- drivers/dstate.c | 2 +- drivers/gamatronic.c | 7 +++---- drivers/isbmex.c | 2 +- drivers/mge-utalk.c | 20 +++++++++----------- drivers/nut-libfreeipmi.c | 4 ++-- drivers/nutdrv_qx_voltronic-qs-hex.c | 2 +- drivers/nutdrv_qx_voltronic.c | 6 +++--- drivers/oneac.c | 2 +- drivers/powercom.c | 8 ++++---- drivers/rhino.c | 2 +- drivers/riello_ser.c | 1 - drivers/snmp-ups.c | 2 +- drivers/solis.c | 5 ++--- drivers/tripplite_usb.c | 2 +- drivers/tripplitesu.c | 2 +- server/netssl.c | 2 +- tools/nut-scanner/scan_nut.c | 26 ++++++++++++-------------- 26 files changed, 58 insertions(+), 65 deletions(-) diff --git a/clients/cgilib.c b/clients/cgilib.c index 2eb9ce8721..28e99382ff 100644 --- a/clients/cgilib.c +++ b/clients/cgilib.c @@ -46,7 +46,7 @@ static char *unescape(char *buf) hex[1] = buf[++i]; hex[2] = '\0'; if (!isxdigit((unsigned char) hex[0]) - || !isxdigit((unsigned char) hex[0])) + || !isxdigit((unsigned char) hex[1])) fatalx(EXIT_FAILURE, "bad escape char"); ch = strtol(hex, NULL, 16); diff --git a/clients/nutclient.cpp b/clients/nutclient.cpp index b597e0e1e6..c8f03a4696 100644 --- a/clients/nutclient.cpp +++ b/clients/nutclient.cpp @@ -505,6 +505,7 @@ TcpClient::TcpClient(): Client(), _host("localhost"), _port(3493), +_timeout(0), _socket(new internal::Socket) { // Do not connect now @@ -512,6 +513,7 @@ _socket(new internal::Socket) TcpClient::TcpClient(const std::string& host, int port)throw(IOException): Client(), +_timeout(0), _socket(new internal::Socket) { connect(host, port); @@ -893,7 +895,7 @@ std::string TcpClient::sendQuery(const std::string& req)throw(IOException) void TcpClient::sendAsyncQueries(const std::vector& req)throw(IOException) { - for (std::vector::const_iterator it = req.cbegin(); it != req.cend(); it++) + for (std::vector::const_iterator it = req.cbegin(); it != req.cend(); ++it) { _socket->write(*it); } diff --git a/clients/upsmon.c b/clients/upsmon.c index 39c61ba6dc..4ea43226c0 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -916,10 +916,7 @@ static void addups(int reloading, const char *sys, const char *pvs, /* build this up so the user doesn't run with bad settings */ totalpv += tmp->pv; - if (un) - tmp->un = xstrdup(un); - else - tmp->un = NULL; + tmp->un = xstrdup(un); tmp->pw = xstrdup(pw); tmp->status = 0; diff --git a/clients/upsset.c b/clients/upsset.c index 8f18b7cdb1..4a9fbda53e 100644 --- a/clients/upsset.c +++ b/clients/upsset.c @@ -391,7 +391,7 @@ static void showcmds(void) /* CMD upsname cmdname */ if (numa < 3) { fprintf(stderr, "Error: insufficient data " - "(got %d args, need at least 3)\n", numa); + "(got %u args, need at least 3)\n", numa); return; } @@ -661,6 +661,7 @@ static void do_enum(const char *varname) printf("Unavailable\n"); fprintf(stderr, "Error doing ENUM %s %s: %s\n", upsname, varname, upscli_strerror(&ups)); + free(val); return; } @@ -674,7 +675,7 @@ static void do_enum(const char *varname) if (numa < 4) { fprintf(stderr, "Error: insufficient data " - "(got %d args, need at least 4)\n", numa); + "(got %u args, need at least 4)\n", numa); free(val); return; diff --git a/drivers/al175.c b/drivers/al175.c index 7d0b02e57e..a6ea4cf633 100644 --- a/drivers/al175.c +++ b/drivers/al175.c @@ -531,7 +531,7 @@ static int al_parse_reply(io_head_t *io_head, raw_data_t *io_buf, /*const*/ raw_ int err; unsigned i; - const byte_t *reply = raw_reply.begin - 1; + const byte_t *reply = NULL; /* 1: extract header and parse it */ /*const*/ raw_data_t raw_reply_head = raw_reply; diff --git a/drivers/apcsmart-old.c b/drivers/apcsmart-old.c index 5c06372ee5..2f16037fd6 100644 --- a/drivers/apcsmart-old.c +++ b/drivers/apcsmart-old.c @@ -919,7 +919,7 @@ static int (*sdlist[])(int) = { static void upsdrv_shutdown_simple(int status) { - unsigned int sdtype = 0; + long sdtype = 0; char *strval; if ((strval = getval("sdtype"))) { diff --git a/drivers/asem.c b/drivers/asem.c index d5d6ea511a..2f7ad4dbeb 100644 --- a/drivers/asem.c +++ b/drivers/asem.c @@ -245,7 +245,7 @@ void upsdrv_updateinfo(void) status_init(); status_set(online ? "OL" : "OB"); - if (!discharging & !fully_charged) + if (!discharging && !fully_charged) status_set("CHRG"); else if (discharging && current < 0) status_set("DISCHRG"); diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index 6fb2f86413..d38a19c668 100644 --- a/drivers/bcmxcp.c +++ b/drivers/bcmxcp.c @@ -782,7 +782,7 @@ bool_t init_command(int size) for (ncounter = 0; ncounter < NumComms; ncounter++) { commandByte = answer[iIndex]; - if(commandByte >= 0 && commandByte < BCMXCP_COMMAND_MAP_MAX) { + if(commandByte < BCMXCP_COMMAND_MAP_MAX) { upsdebugx(2, "%03d\t%02x\t%s", ncounter, commandByte, bcmxcp_command_map[commandByte].command_desc); bcmxcp_command_map[commandByte].command_byte = commandByte; } diff --git a/drivers/belkinunv.c b/drivers/belkinunv.c index c5abda2fe7..d6cc525569 100644 --- a/drivers/belkinunv.c +++ b/drivers/belkinunv.c @@ -919,7 +919,7 @@ void upsdrv_initinfo(void) val = belkin_nut_read_int(REG_ALARMSTATUS); if (val!=-1) { - dstate_setinfo("ups.beeper.status", "%s", val==1 ? "disabled" : val&1 ? "muted" : "enabled"); + dstate_setinfo("ups.beeper.status", "%s", (val==1) ? "disabled" : (val&1) ? "muted" : "enabled"); /* declare variable writable */ dstate_setflags("ups.beeper.status", ST_FLAG_RW); @@ -1060,7 +1060,7 @@ void upsdrv_updateinfo(void) val = belkin_nut_read_int(REG_ALARMSTATUS); if (val!=-1) { - dstate_setinfo("ups.beeper.status", "%s", val==1 ? "disabled" : val&1 ? "muted" : "enabled"); + dstate_setinfo("ups.beeper.status", "%s", (val==1) ? "disabled" : (val&1) ? "muted" : "enabled"); } val = belkin_nut_read_int(REG_SHUTDOWNTIMER); diff --git a/drivers/dstate.c b/drivers/dstate.c index 51e41a052a..90ee7719f2 100644 --- a/drivers/dstate.c +++ b/drivers/dstate.c @@ -1167,7 +1167,7 @@ int dstate_detect_phasecount( if ( (v1 && v2 && !v3) || (v1n && v2n && !v3n) || - (c1 && c2 && !c2) || + (c1 && c2 && !c3) || (v12 && !v23 && !v31) ) { upsdebugx(5, "%s(): determined a 2-phase case", __func__); *num_phases = 2; diff --git a/drivers/gamatronic.c b/drivers/gamatronic.c index a4f5a57bf3..d1fe7de624 100644 --- a/drivers/gamatronic.c +++ b/drivers/gamatronic.c @@ -108,10 +108,9 @@ int sec_cmd(const char mode, const char *command, char *msgbuf, int *buflen) if (ret < 0) return -1; - if (ret >= 0) { - strncpy(msgbuf, msg, ret); - upsdebugx(1, "UPS<--PC: \"%s\"",msg); - } + strncpy(msgbuf, msg, ret); + upsdebugx(1, "UPS<--PC: \"%s\"",msg); + /* *(msgbuf+ret) = '\0';*/ *buflen = ret; diff --git a/drivers/isbmex.c b/drivers/isbmex.c index 17328b2abe..69e4ada4d6 100644 --- a/drivers/isbmex.c +++ b/drivers/isbmex.c @@ -175,7 +175,7 @@ static const char *getpacket(int *we_know){ } r=read(upsfd,buf,255); - D(printf("%d bytes read: ",r);) + D(printf("%zd bytes read: ",r);) buf[r]=0; if (bytes_per_packet && r < bytes_per_packet){ ssize_t rr; diff --git a/drivers/mge-utalk.c b/drivers/mge-utalk.c index 2935e91d68..3ceffe6c01 100644 --- a/drivers/mge-utalk.c +++ b/drivers/mge-utalk.c @@ -896,19 +896,17 @@ static int mge_command(char *reply, int replylen, const char *fmt, ...) } /* send terminating string */ - if (MGE_COMMAND_ENDCHAR) { - for (p = MGE_COMMAND_ENDCHAR; *p; p++) { - if ( isprint(*p & 0xFF) ) - upsdebugx(4, "mge_command: sending [%c]", *p); - else - upsdebugx(4, "mge_command: sending [%02X]", *p); + for (p = MGE_COMMAND_ENDCHAR; *p; p++) { + if ( isprint(*p & 0xFF) ) + upsdebugx(4, "mge_command: sending [%c]", *p); + else + upsdebugx(4, "mge_command: sending [%02X]", *p); - if (write(upsfd, p, 1) != 1) - return -1; + if (write(upsfd, p, 1) != 1) + return -1; - bytes_sent++; - usleep(MGE_CHAR_DELAY); - } + bytes_sent++; + usleep(MGE_CHAR_DELAY); } if ( !reply ) diff --git a/drivers/nut-libfreeipmi.c b/drivers/nut-libfreeipmi.c index 06e955e3bb..80db729eac 100644 --- a/drivers/nut-libfreeipmi.c +++ b/drivers/nut-libfreeipmi.c @@ -861,7 +861,7 @@ int nut_ipmi_get_sensors_status(IPMIDevice_t *ipmi_dev) * if ((sensor_state = ipmi_monitoring_sensor_read_sensor_state (mon_ctx)) < 0) * ... */ - if ((sensor_reading = ipmi_monitoring_sensor_read_sensor_reading (mon_ctx)) < 0) + if ((sensor_reading = ipmi_monitoring_sensor_read_sensor_reading (mon_ctx)) == NULL) { upsdebugx (1, "ipmi_monitoring_sensor_read_sensor_reading() error: %s", ipmi_monitoring_ctx_errormsg (mon_ctx)); @@ -881,7 +881,7 @@ int nut_ipmi_get_sensors_status(IPMIDevice_t *ipmi_dev) continue; } - if ((sensor_bitmask_strings = ipmi_monitoring_sensor_read_sensor_bitmask_strings (mon_ctx)) < 0) + if ((sensor_bitmask_strings = ipmi_monitoring_sensor_read_sensor_bitmask_strings (mon_ctx)) == NULL) { upsdebugx (1, "ipmi_monitoring_sensor_read_sensor_bitmask_strings() error: %s", ipmi_monitoring_ctx_errormsg (mon_ctx)); diff --git a/drivers/nutdrv_qx_voltronic-qs-hex.c b/drivers/nutdrv_qx_voltronic-qs-hex.c index 6b21acdf11..6e05661ae9 100644 --- a/drivers/nutdrv_qx_voltronic-qs-hex.c +++ b/drivers/nutdrv_qx_voltronic-qs-hex.c @@ -219,7 +219,7 @@ static int voltronic_qs_hex_preprocess_qs_answer(item_t *item, const int len) } /* 'Unescape' raw data */ - if (item->answer[i] == 0x28 && i < len) { + if (i < len && item->answer[i] == 0x28) { switch (item->answer[i + 1]) { diff --git a/drivers/nutdrv_qx_voltronic.c b/drivers/nutdrv_qx_voltronic.c index 3ab33a630f..292fd32822 100644 --- a/drivers/nutdrv_qx_voltronic.c +++ b/drivers/nutdrv_qx_voltronic.c @@ -267,7 +267,7 @@ static int voltronic_bypass_volt_max(char *value, const size_t len) if (ivn >= 200) return -1; - if (protocol == 2 || protocol == 2 || protocol == 10 || protocol == 13 || protocol == 14) + if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 13 || protocol == 14) // •••Sean••• not sure... a guess from the comment above return 0; break; @@ -300,7 +300,7 @@ static int voltronic_bypass_volt_max(char *value, const size_t len) if (ivn < 200) return -1; - if (protocol == 2 || protocol == 2 || protocol == 10 || protocol == 13 || protocol == 14 || protocol == 99) + if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 13 || protocol == 14 || protocol == 99) return 0; break; @@ -394,7 +394,7 @@ static int voltronic_bypass_volt_min(char *value, const size_t len) if (ivn >= 200) return -1; - if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 10 || protocol == 13 || protocol == 14) + if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 13 || protocol == 14) return 0; break; diff --git a/drivers/oneac.c b/drivers/oneac.c index 55035f7bbd..862c7707d7 100644 --- a/drivers/oneac.c +++ b/drivers/oneac.c @@ -173,7 +173,7 @@ void EliminateLeadingZeroes (const char* buff1, int StringSize, char* buff2, memset(buff2, '\0', buff2size); /* Fill with nulls */ /* Find first non-'0' */ - while ((buff1[i] == '0') && (i < (StringSize - 1))) + while ((i < (StringSize - 1) && (buff1[i] == '0'))) { i++; } diff --git a/drivers/powercom.c b/drivers/powercom.c index edf2b9b4fd..1898ced984 100644 --- a/drivers/powercom.c +++ b/drivers/powercom.c @@ -674,7 +674,7 @@ static float load_level(void) } else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) { return raw_data[UPS_LOAD]; } - return raw_data[STATUS_A] & MAINS_FAILURE ? + return (raw_data[STATUS_A] & MAINS_FAILURE) ? types[type].loadpct[0] * raw_data[UPS_LOAD] + types[type].loadpct[1] : types[type].loadpct[2] * raw_data[UPS_LOAD] + @@ -693,9 +693,9 @@ static float batt_level(void) battval=(raw_data[UPS_LOAD])/4+raw_data[BATTERY_CHARGE]; if (battval<=bat0) return 0.0; - if (battval>bat0 && battval<=bat29) + if (battval<=bat29) return (battval-bat0)*30.0/(bat29-bat0); - if (battval>bat29 && battval<=bat100) + if (battval<=bat100) return 30.0+(battval-bat29)*70.0/(bat100-bat29); return 100.0; } @@ -729,7 +729,7 @@ static float batt_level(void) } if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) return raw_data[BATTERY_CHARGE]; - return raw_data[STATUS_A] & ONLINE ? /* Are we on battery power? */ + return (raw_data[STATUS_A] & ONLINE) ? /* Are we on battery power? */ /* Yes */ types[type].battpct[0] * raw_data[BATTERY_CHARGE] + types[type].battpct[1] * load_level() + types[type].battpct[2] : diff --git a/drivers/rhino.c b/drivers/rhino.c index c43c411b1c..79db048370 100644 --- a/drivers/rhino.c +++ b/drivers/rhino.c @@ -187,7 +187,7 @@ AutonomyCalc( int ia ) /* all models */ { currin = ( UtilPowerOut + ConstInt ) *1.0 / Vin; auton = ( ( ( AmpH *1.0 / currin ) * 60 * ( ( BattVoltage - VbatMin ) * 1.0 /( VbatNom - VbatMin ) ) * FM ) + FA ); - if( ( BattVoltage > 129 ) || ( BattVoltage < 144 ) ) + if( ( BattVoltage > 129 ) && ( BattVoltage < 144 ) ) result = 133; else result = (int) auton; diff --git a/drivers/riello_ser.c b/drivers/riello_ser.c index 9ee779dd1f..088d3f29c2 100644 --- a/drivers/riello_ser.c +++ b/drivers/riello_ser.c @@ -102,7 +102,6 @@ static int char_read (char *bytes, int size, int read_timeout) return -1; } else { - bytes += now; readen += now; } } diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index e32c5643b8..d0a9dbeb99 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -1551,7 +1551,7 @@ bool_t is_multiple_template(const char *OID_template) * Note: remember to adapt info_type, OID and optionaly dfl */ snmp_info_t *instantiate_info(snmp_info_t *info_template, snmp_info_t *new_instance) { - upsdebugx(1, "%s(%s)", __func__, info_template->info_type); + upsdebugx(1, "%s(%s)", __func__, info_template ? info_template->info_type : "n/a"); /* sanity check */ if (info_template == NULL) diff --git a/drivers/solis.c b/drivers/solis.c index c175dd8389..fed2b446e0 100644 --- a/drivers/solis.c +++ b/drivers/solis.c @@ -479,7 +479,7 @@ static void scan_received_pack(void) { if (!SourceFail && InversorOn) OutFreq = InFreq; - if (AppPower <= 0) /* charge pf */ + if (AppPower < 0) /* charge pf */ // •••Sean••• not sure... ChargePowerFactor = 0; else { if( AppPower == 0 ) @@ -722,8 +722,7 @@ static void get_base_info(void) { } else { if (i2 == 1 && DaysOffWeek > 0) { isprogram = 1; - if (DaysOnWeek != DaysOffWeek) - DaysOnWeek = DaysOffWeek; + DaysOnWeek = DaysOffWeek; } } } /* end prgups 1 - 2 */ diff --git a/drivers/tripplite_usb.c b/drivers/tripplite_usb.c index 82efe35d8d..7d205583ac 100644 --- a/drivers/tripplite_usb.c +++ b/drivers/tripplite_usb.c @@ -576,7 +576,7 @@ static int send_cmd(const unsigned char *msg, size_t msg_len, unsigned char *rep } #if ! defined(__FreeBSD__) - if(!done) { usleep(1000*100); /* TODO: nanosleep */ } + usleep(1000*100); /* TODO: nanosleep */ #endif for(recv_try=0; !done && recv_try < MAX_RECV_TRIES; recv_try++) { diff --git a/drivers/tripplitesu.c b/drivers/tripplitesu.c index 2f6dd2b38d..6ce5df8a32 100644 --- a/drivers/tripplitesu.c +++ b/drivers/tripplitesu.c @@ -432,7 +432,7 @@ static void set_sensitivity(const char *val) { for (i = 0; i < sizeof(sensitivity) / sizeof(sensitivity[0]); i++) { if (!strcasecmp(val, sensitivity[i].name)) { - snprintf(parm, sizeof(parm), "%d", i); + snprintf(parm, sizeof(parm), "%u", i); do_command(SET, VOLTAGE_SENSITIVITY, parm, NULL); break; } diff --git a/server/netssl.c b/server/netssl.c index cf9419edf8..74ee186f56 100644 --- a/server/netssl.c +++ b/server/netssl.c @@ -531,7 +531,7 @@ void ssl_init(void) int ssl_read(nut_ctype_t *client, char *buf, size_t buflen) { - int ret; + int ret = -1; if (!client->ssl_connected) { return -1; diff --git a/tools/nut-scanner/scan_nut.c b/tools/nut-scanner/scan_nut.c index 0a5dbd3310..57758f581b 100644 --- a/tools/nut-scanner/scan_nut.c +++ b/tools/nut-scanner/scan_nut.c @@ -177,24 +177,22 @@ static void * list_nut_devices(void * arg) /* FIXME: * - also print answer[2] if != "Unavailable"? * - for upsmon.conf or ups.conf (using dummy-ups)? */ - if (numa >= 3) { - dev = nutscan_new_device(); - dev->type = TYPE_NUT; - dev->driver = strdup("nutclient"); - /* +1+1 is for '@' character and terminating 0 */ - buf_size = strlen(answer[1])+strlen(hostname)+1+1; - dev->port = malloc(buf_size); - if( dev->port ) { - snprintf(dev->port,buf_size,"%s@%s",answer[1], - hostname); + dev = nutscan_new_device(); + dev->type = TYPE_NUT; + dev->driver = strdup("nutclient"); + /* +1+1 is for '@' character and terminating 0 */ + buf_size = strlen(answer[1])+strlen(hostname)+1+1; + dev->port = malloc(buf_size); + if( dev->port ) { + snprintf(dev->port,buf_size,"%s@%s",answer[1], + hostname); #ifdef HAVE_PTHREAD - pthread_mutex_lock(&dev_mutex); + pthread_mutex_lock(&dev_mutex); #endif - dev_ret = nutscan_add_device_to_device(dev_ret,dev); + dev_ret = nutscan_add_device_to_device(dev_ret,dev); #ifdef HAVE_PTHREAD - pthread_mutex_unlock(&dev_mutex); + pthread_mutex_unlock(&dev_mutex); #endif - } } } From cb0200249c79df689f29bb37dd4a475489657d11 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 4 Nov 2020 13:59:06 +0100 Subject: [PATCH 2/3] Update nutdrv_qx_voltronic.c Drop temporary comment with unicode for PR --- drivers/nutdrv_qx_voltronic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nutdrv_qx_voltronic.c b/drivers/nutdrv_qx_voltronic.c index 292fd32822..11f05dc70e 100644 --- a/drivers/nutdrv_qx_voltronic.c +++ b/drivers/nutdrv_qx_voltronic.c @@ -267,7 +267,7 @@ static int voltronic_bypass_volt_max(char *value, const size_t len) if (ivn >= 200) return -1; - if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 13 || protocol == 14) // •••Sean••• not sure... a guess from the comment above + if (protocol == 2 || protocol == 3 || protocol == 10 || protocol == 13 || protocol == 14) return 0; break; From dfb4daed6a6779b336806d1002a3ce8eb806530c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 4 Nov 2020 14:00:55 +0100 Subject: [PATCH 3/3] Update solis.c Drop temporary unicode comment for PR --- drivers/solis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/solis.c b/drivers/solis.c index 9f0bf6f0fe..c7978e8095 100644 --- a/drivers/solis.c +++ b/drivers/solis.c @@ -484,7 +484,7 @@ static void scan_received_pack(void) { if (!SourceFail && InversorOn) OutFreq = InFreq; - if (AppPower < 0) /* charge pf */ // •••Sean••• not sure... + if (AppPower < 0) /* charge pf */ ChargePowerFactor = 0; else { if( AppPower == 0 )