core: Fix results returned by gpgme_data_* functions

src/debug.h (TRACE_SYSRES_OFF_T, _trace_sysres_off_t,
TRACE_SYSRES_SSIZE_T, _trace_sysres_ssize_t): New.
src/data.c (gpgme_data_read, gpgme_data_write, gpgme_data_seek): Use
appropriate new tracing macros instead of casting the results to int.
--

This change adds tracing macros for results of system functions of
type __off_t and __ssize_t.

GnuPG-bug-id: 5481
This commit is contained in:
Ingo Klöcker 2021-08-03 12:09:13 +02:00
parent 4b64774b6d
commit 7cfc93193d
2 changed files with 36 additions and 4 deletions

View File

@ -391,7 +391,7 @@ gpgme_data_read (gpgme_data_t dh, void *buffer, size_t size)
while (res < 0 && errno == EINTR); while (res < 0 && errno == EINTR);
} }
return TRACE_SYSRES ((int)res); return TRACE_SYSRES_SSIZE_T (res);
} }
@ -419,7 +419,7 @@ gpgme_data_write (gpgme_data_t dh, const void *buffer, size_t size)
res = (*dh->cbs->write) (dh, buffer, size); res = (*dh->cbs->write) (dh, buffer, size);
while (res < 0 && errno == EINTR); while (res < 0 && errno == EINTR);
return TRACE_SYSRES ((int)res); return TRACE_SYSRES_SSIZE_T (res);
} }
@ -452,7 +452,7 @@ gpgme_data_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
if (offset >= 0) if (offset >= 0)
dh->outbound_pending = 0; dh->outbound_pending = 0;
return TRACE_SYSRES ((int)offset); return TRACE_SYSRES_OFF_T (offset);
} }

View File

@ -141,7 +141,7 @@ _trace_err (gpg_error_t err, int lvl, const char *func, int line)
return err; return err;
} }
/* Trace a system call result and return it. */ /* Trace a system call result of type int and return it. */
#define TRACE_SYSRES(res) \ #define TRACE_SYSRES(res) \
_trace_sysres ((res), _gpgme_trace_level, _gpgme_trace_func, __LINE__) _trace_sysres ((res), _gpgme_trace_level, _gpgme_trace_func, __LINE__)
static inline int static inline int
@ -157,6 +157,38 @@ _trace_sysres (int res, int lvl, const char *func, int line)
return res; return res;
} }
/* Trace a system call result of type gpgme_off_t and return it. */
#define TRACE_SYSRES_OFF_T(res) \
_trace_sysres_off_t ((res), _gpgme_trace_level, _gpgme_trace_func, __LINE__)
static inline gpgme_off_t
_trace_sysres_off_t (gpgme_off_t res, int lvl, const char *func, int line)
{
if (res >= 0)
_gpgme_debug (NULL, lvl, 3, func, NULL, NULL, "result=%ld", res);
else
_gpgme_debug (NULL, lvl, -1, NULL, NULL, NULL,
"%s:%d: error: %s (%d)\n",
func, line, strerror (errno), errno);
_gpgme_debug_frame_end ();
return res;
}
/* Trace a system call result of type gpgme_ssize_t and return it. */
#define TRACE_SYSRES_SSIZE_T(res) \
_trace_sysres_ssize_t ((res), _gpgme_trace_level, _gpgme_trace_func, __LINE__)
static inline gpgme_ssize_t
_trace_sysres_ssize_t (gpgme_ssize_t res, int lvl, const char *func, int line)
{
if (res >= 0)
_gpgme_debug (NULL, lvl, 3, func, NULL, NULL, "result=%zd", res);
else
_gpgme_debug (NULL, lvl, -1, NULL, NULL, NULL,
"%s:%d: error: %s (%d)\n",
func, line, strerror (errno), errno);
_gpgme_debug_frame_end ();
return res;
}
/* Trace a system call error and return it. */ /* Trace a system call error and return it. */
#define TRACE_SYSERR(rc) \ #define TRACE_SYSERR(rc) \
_trace_syserr ((rc), _gpgme_trace_level, _gpgme_trace_func, __LINE__) _trace_syserr ((rc), _gpgme_trace_level, _gpgme_trace_func, __LINE__)