|
From: <kin...@us...> - 2025-09-28 08:49:43
|
Revision: 7509
http://sourceforge.net/p/teem/code/7509
Author: kindlmann
Date: 2025-09-28 08:49:41 +0000 (Sun, 28 Sep 2025)
Log Message:
-----------
helper function to avoid warnings about snprintf %s directive output may be truncated writing up to ...
Modified Paths:
--------------
teem/trunk/src/air/air.h
teem/trunk/src/air/string.c
Modified: teem/trunk/src/air/air.h
===================================================================
--- teem/trunk/src/air/air.h 2025-09-28 08:25:44 UTC (rev 7508)
+++ teem/trunk/src/air/air.h 2025-09-28 08:49:41 UTC (rev 7509)
@@ -514,6 +514,7 @@
AIR_EXPORT char *airStrdup(const char *s);
AIR_EXPORT size_t airStrlen(const char *s);
/* ---- BEGIN non-NrrdIO */
+AIR_EXPORT char *airStrtrunc(char *s, size_t bsize, size_t drop);
AIR_EXPORT int airStrcmp(const char *s1, const char *s2);
/* ---- END non-NrrdIO */
AIR_EXPORT char *airStrtok(char *s, const char *ct, char **last);
Modified: teem/trunk/src/air/string.c
===================================================================
--- teem/trunk/src/air/string.c 2025-09-28 08:25:44 UTC (rev 7508)
+++ teem/trunk/src/air/string.c 2025-09-28 08:49:41 UTC (rev 7509)
@@ -65,6 +65,21 @@
/* ---- BEGIN non-NrrdIO */
/*
+(possibly) truncates a given string `str` stored in a buffer of size `bsize`
+to ensure that its strlen does not exceed bsize-1-drop. But main purpose is
+to hide compile-time info about static buffer sizes to avoid warnings about:
+snprintf ...'%s' directive output may be truncated writing up to ... */
+char *
+airStrtrunc(char *str, size_t bsize, size_t drop) {
+ if (str) {
+ if (1 + drop < bsize) {
+ str[bsize - (1 + drop)] = '\0';
+ }
+ }
+ return str;
+}
+
+/*
******** airStrcmp
**
** like strcmp, but:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|