Skip to content

Commit

Permalink
Fix for use of non portable strnstr function
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Dec 23, 2019
1 parent 38337d6 commit 54ec927
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "config.h"
#include "section.h"
#include "message.h"
#include "portable.h"

//-----------

Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions src/portable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(memmem(haystack, haystack_len, needle, needle_len));
if (x && !memchr(haystack, 0, x - haystack))
{
return x;
}
}
return 0;
}
1 change: 1 addition & 0 deletions src/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit 54ec927

Please sign in to comment.