Skip to content

Commit

Permalink
fix GCC analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Mar 28, 2024
1 parent c225d6e commit 51126b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
35 changes: 20 additions & 15 deletions src/c4/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,33 +151,38 @@ bool is_debugger_attached()
if(first_call)
{
first_call = false;
C4_SUPPRESS_WARNING_GCC_PUSH
#if defined(__GNUC__) && __GNUC__ > 9
C4_SUPPRESS_WARNING_GCC("-Wanalyzer-fd-leak")
#endif
//! @see http://stackoverflow.com/questions/3596781/how-to-detect-if-the-current-process-is-being-run-by-gdb
//! (this answer: http://stackoverflow.com/a/24969863/3968589 )
char buf[1024] = "";

int status_fd = open("/proc/self/status", O_RDONLY);
if (status_fd == -1)
{
return 0;
}

ssize_t num_read = ::read(status_fd, buf, sizeof(buf));

if (num_read > 0)
else
{
static const char TracerPid[] = "TracerPid:";
char *tracer_pid;

if(num_read < 1024)
{
buf[num_read] = 0;
}
tracer_pid = strstr(buf, TracerPid);
if (tracer_pid)
ssize_t num_read = ::read(status_fd, buf, sizeof(buf));
if (num_read > 0)
{
first_call_result = !!::atoi(tracer_pid + sizeof(TracerPid) - 1);
static const char TracerPid[] = "TracerPid:";
char *tracer_pid;
if(num_read < 1024)
{
buf[num_read] = 0;
}
tracer_pid = strstr(buf, TracerPid);
if (tracer_pid)
{
first_call_result = !!::atoi(tracer_pid + sizeof(TracerPid) - 1);
}
}
close(status_fd);
}
C4_SUPPRESS_WARNING_GCC_POP
}
return first_call_result;
#elif defined(C4_PS4)
Expand Down
6 changes: 5 additions & 1 deletion src/c4/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ bool from_chars(csubstr buf, fmt::raw_wrapper *r)
auto ptr = (decltype(buf.str)) std::align(r->alignment, r->len, vptr, space);
C4_CHECK(ptr != nullptr);
C4_CHECK(ptr >= buf.begin() && ptr <= buf.end());
//size_t dim = (ptr - buf.str) + r->len;
C4_SUPPRESS_WARNING_GCC_PUSH
#if defined(__GNUC__) && __GNUC__ > 9
C4_SUPPRESS_WARNING_GCC("-Wanalyzer-null-argument")
#endif
memcpy(r->buf, ptr, r->len);
C4_SUPPRESS_WARNING_GCC_POP
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_charconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")
C4_SUPPRESS_WARNING_GCC("-Wconversion")
C4_SUPPRESS_WARNING_GCC("-Wtype-limits")
C4_SUPPRESS_WARNING_GCC("-Wfloat-equal")
#if defined (__GNUC__) && __GNUC_MAJOR__ >= 7
#if defined (__GNUC__) && __GNUC__ >= 9
C4_SUPPRESS_WARNING_GCC("-Wno-noexcept-type")
#endif
C4_SUPPRESS_WARNING_CLANG_PUSH
Expand Down

0 comments on commit 51126b3

Please sign in to comment.