@cryptotaxi247 / netdata-1 / commits / ab0486989

Fix coverity issue 394862 - Argument cannot be negative (#15324)

* Fix coverity 394862 - Argument cannot be negative * If GUID write fails, no point in trying to add newline

Stelios Fragkakis committed Jul 7, 2023 at 15:39 UTC ab04869892bf2b20f95e1f69cc1dbbabd06505e5
1 file changed +7 -9
claim/claim.c
+7 -9
@@ -253,17 +253,15 @@ bool netdata_random_session_id_generate(void) {
253 netdata_log_error("Cannot create random session id file '%s'.", filename);
254 ret = false;
255 }
256 -
257 - if(write(fd, guid, UUID_STR_LEN - 1) != UUID_STR_LEN - 1) {
258 - netdata_log_error("Cannot write the random session id file '%s'.", filename);
259 - ret = false;
256 + else {
257 + if (write(fd, guid, UUID_STR_LEN - 1) != UUID_STR_LEN - 1) {
258 + netdata_log_error("Cannot write the random session id file '%s'.", filename);
259 + ret = false;
260 + } else
261 + (void) write(fd, "\n", 1);
262 + close(fd);
263 }
264
262 - ssize_t rc = write(fd, "\n", 1);
263 - (void)rc;
264 -
265 - close(fd);
266 -
265 if(ret && (!netdata_random_session_id_filename || strcmp(netdata_random_session_id_filename, filename) != 0)) {
266 freez(netdata_random_session_id_filename);
267 netdata_random_session_id_filename = strdupz(filename);