utils: fix -Wsign-compare in definition of OSMO_STRBUF_CHAR_COUNT
We're seeing tons of -Wsign-compare warnings since I merged 0f59cebf:
include/osmocom/core/utils.h: In function 'size_t _osmo_strbuf_char_count(const osmo_strbuf*)':
include/osmocom/core/utils.h:24:29: error: comparison of integer expressions of different
signedness: 'long int' and 'long unsigned int'
[-Werror=sign-compare]
24 | #define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
| ~~~~^~~~~~
include/osmocom/core/utils.h:309:16: note: in expansion of macro 'OSMO_MIN'
309 | return OSMO_MIN(sb->pos - sb->buf, sb->len - 1);
| ^~~~~~~~
Interestingly enough, this -Wsign-compare problem has always been the
case, even before commit 0f59cebf. And somehow this did not show up
when building libosmocore.git, but only when building C++ projects
(osmo-pcu and osmo-trx).
Perhaps it has something to do with how g++ compiles extern "C" code.
Change-Id: I8e396459409e4260b8715f9e890e8972d4609a31
Fixes: 0f59cebf "utils: improve readability of OSMO_STRBUF_CHAR_COUNT"
diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index 9a6e6b2..92bea59 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -306,7 +306,7 @@
return 0;
if (sb->pos == NULL || sb->pos <= sb->buf)
return 0;
- return OSMO_MIN(sb->pos - sb->buf, sb->len - 1);
+ return OSMO_MIN((size_t)(sb->pos - sb->buf), sb->len - 1);
}
/*! Return number of actual characters contained in struct osmo_strbuf (without terminating nul). */