From 54ec927d886b895b1ec7bbe62c143b052970fdf6 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Mon, 23 Dec 2019 14:03:44 +0100 Subject: Fix for use of non portable strnstr function --- src/markdown.cpp | 3 ++- src/portable.cpp | 15 +++++++++++++++ src/portable.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/markdown.cpp b/src/markdown.cpp index 0a71aae..8594a15 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -51,6 +51,7 @@ #include "config.h" #include "section.h" #include "message.h" +#include "portable.h" //----------- @@ -1031,7 +1032,7 @@ static int processCodeSpan(GrowBuf &out, const char *data, int /*offset*/, int s static void addStrEscapeUtf8Nbsp(GrowBuf &out,const char *s,int len) { - if (strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast + if (Portable::strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast { out.addStr(s,len); } diff --git a/src/portable.cpp b/src/portable.cpp index 1134351..9927c45 100644 --- a/src/portable.cpp +++ b/src/portable.cpp @@ -475,3 +475,18 @@ void Portable::setShortDir(void) delete [] buffer; #endif } + + +char *Portable::strnstr(const char *haystack, const char *needle, size_t haystack_len) +{ + size_t needle_len = strnlen(needle, haystack_len); + if (needle_len < haystack_len || !needle[needle_len]) + { + char *x = static_cast(memmem(haystack, haystack_len, needle, needle_len)); + if (x && !memchr(haystack, 0, x - haystack)) + { + return x; + } + } + return 0; +} diff --git a/src/portable.h b/src/portable.h index 27b7052..be73435 100644 --- a/src/portable.h +++ b/src/portable.h @@ -42,6 +42,7 @@ namespace Portable bool isAbsolutePath(const char *fileName); void correct_path(void); void setShortDir(void); + char * strnstr(const char *haystack, const char *needle, size_t haystack_len); } -- cgit v0.12