Skip to content

Commit 54ec927

Browse files
committed
Fix for use of non portable strnstr function
1 parent 38337d6 commit 54ec927

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/markdown.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "config.h"
5252
#include "section.h"
5353
#include "message.h"
54+
#include "portable.h"
5455

5556
//-----------
5657

@@ -1031,7 +1032,7 @@ static int processCodeSpan(GrowBuf &out, const char *data, int /*offset*/, int s
10311032

10321033
static void addStrEscapeUtf8Nbsp(GrowBuf &out,const char *s,int len)
10331034
{
1034-
if (strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast
1035+
if (Portable::strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast
10351036
{
10361037
out.addStr(s,len);
10371038
}

src/portable.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,18 @@ void Portable::setShortDir(void)
475475
delete [] buffer;
476476
#endif
477477
}
478+
479+
480+
char *Portable::strnstr(const char *haystack, const char *needle, size_t haystack_len)
481+
{
482+
size_t needle_len = strnlen(needle, haystack_len);
483+
if (needle_len < haystack_len || !needle[needle_len])
484+
{
485+
char *x = static_cast<char*>(memmem(haystack, haystack_len, needle, needle_len));
486+
if (x && !memchr(haystack, 0, x - haystack))
487+
{
488+
return x;
489+
}
490+
}
491+
return 0;
492+
}

src/portable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Portable
4242
bool isAbsolutePath(const char *fileName);
4343
void correct_path(void);
4444
void setShortDir(void);
45+
char * strnstr(const char *haystack, const char *needle, size_t haystack_len);
4546
}
4647

4748

0 commit comments

Comments
 (0)