diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2023-07-07 15:39:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-07 15:39:40 +0300 |
commit | ab04869892bf2b20f95e1f69cc1dbbabd06505e5 (patch) | |
tree | c277e534f958a816c37742bf03d08037392ffd54 /claim | |
parent | 9a5a59885530822f16ccd8cacb1aeaafe934db45 (diff) |
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
Diffstat (limited to 'claim')
-rw-r--r-- | claim/claim.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/claim/claim.c b/claim/claim.c index 4e4161b2d5..6a9f75ef45 100644 --- a/claim/claim.c +++ b/claim/claim.c @@ -253,17 +253,15 @@ bool netdata_random_session_id_generate(void) { netdata_log_error("Cannot create random session id file '%s'.", filename); ret = false; } - - if(write(fd, guid, UUID_STR_LEN - 1) != UUID_STR_LEN - 1) { - netdata_log_error("Cannot write the random session id file '%s'.", filename); - ret = false; + else { + if (write(fd, guid, UUID_STR_LEN - 1) != UUID_STR_LEN - 1) { + netdata_log_error("Cannot write the random session id file '%s'.", filename); + ret = false; + } else + (void) write(fd, "\n", 1); + close(fd); } - ssize_t rc = write(fd, "\n", 1); - (void)rc; - - close(fd); - if(ret && (!netdata_random_session_id_filename || strcmp(netdata_random_session_id_filename, filename) != 0)) { freez(netdata_random_session_id_filename); netdata_random_session_id_filename = strdupz(filename); |