On 09/12/18 12:09 AM, Walter Harms wrote:


Peter Hutterer <peter.hutte...@who-t.net> hat am 12. September 2018 um 06:50
geschrieben:


Fixes coverity complaints about potentially unterminated strings

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
  sessreg.c | 26 +++++++++++++++++---------
  1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/sessreg.c b/sessreg.c
index 0a8fdb2..53b30b0 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -192,6 +192,14 @@ sysnerr (int x, const char *s)
        return x;
  }
+static void
+safe_strncpy(char *dest, const char *src, size_t n)
+{

if you add
      if (!src)
           return;

you can also remove the if (x) before strncpy()

You'd only be able to remove if's from a couple calls so it doesn't seem
like it really buys you much.

I'd be tempted to handle this for non-glibc platforms with something like

#ifdef HAVE_STRLCPY
#define safe_strncpy strlcpy
#else
static void
safe_strncpy(char *dest, const char *src, size_t n)
{
...
}
#endif

which was going to be another argument against it, but I suppose that
could also just be handled via
#define safe_strncpy(d, s, n) do { \
  if (s) { strlcpy(d, s, n); } \
while(0)

--
        -Alan Coopersmith-               alan.coopersm...@oracle.com
         Oracle Solaris Engineering - https://blogs.oracle.com/alanc
_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to