Skip to content

Commit

Permalink
Fixed FreeRDP#8090: Duplicate definition of strndup (FreeRDP#8102)
Browse files Browse the repository at this point in the history
* Fixed FreeRDP#8090: Duplicate definition of strndup

* Moved strndup detection to winpr

Co-authored-by: Armin Novak <[email protected]>
  • Loading branch information
akallabeth and Armin Novak authored Aug 2, 2022
1 parent 0460215 commit bf56a39
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 35 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,6 @@ if(NOT IOS)
find_package(Threads REQUIRED)
endif()

if (IOS)
set(HAVE_STRNDUP 1)
else()
CHECK_SYMBOL_EXISTS(strndup string.h HAVE_STRNDUP)
endif()

# Enable address sanitizer, where supported and when required
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCC)
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
Expand Down
1 change: 0 additions & 1 deletion include/config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#cmakedefine HAVE_SYSLOG_H
#cmakedefine HAVE_JOURNALD_H
#cmakedefine HAVE_VALGRIND_MEMCHECK_H
#cmakedefine HAVE_STRNDUP

/* Features */
#cmakedefine SWRESAMPLE_FOUND
Expand Down
12 changes: 2 additions & 10 deletions libfreerdp/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef FREERDP_LIB_CORE_SETTINGS_H
#define FREERDP_LIB_CORE_SETTINGS_H

#include <winpr/string.h>

#include <freerdp/config.h>

#include <freerdp/types.h>
Expand All @@ -29,16 +31,6 @@

#include <string.h>

#if !defined(HAVE_STRNDUP)
static INLINE char* strndup(const char* src, size_t len)
{
char* dst = calloc(len + 1, sizeof(char));
if (dst)
strncpy(dst, src, len);
return dst;
}
#endif

FREERDP_LOCAL BOOL freerdp_settings_set_default_order_support(rdpSettings* settings);
FREERDP_LOCAL BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src);
FREERDP_LOCAL void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup);
Expand Down
1 change: 0 additions & 1 deletion uwac/templates/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#cmakedefine HAVE_POLL_H
#cmakedefine HAVE_SYSLOG_H
#cmakedefine HAVE_JOURNALD_H
#cmakedefine HAVE_STRNDUP
#cmakedefine HAVE_PIXMAN_REGION

#endif /* UWAC_CONFIG_H */
2 changes: 2 additions & 0 deletions winpr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ else()
endif()

if(NOT IOS)
CHECK_SYMBOL_EXISTS(strndup string.h HAVE_STRNDUP)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(execinfo.h HAVE_EXECINFO_H)
check_include_files(inttypes.h HAVE_INTTYPES_H)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(inttypes.h HAVE_INTTYPES_H)
else(NOT IOS)
set(HAVE_STDINT_H 1)
set(HAVE_STRNDUP 1)
set(HAVE_INTTYPES_H 1)
endif(NOT IOS)

Expand Down
22 changes: 5 additions & 17 deletions winpr/libwinpr/crt/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,23 +646,11 @@ INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
}

#if !defined(HAVE_STRNDUP)
char* strndup(const char* s, size_t n)
char* strndup(const char* src, size_t n)
{
char* rc;
size_t len;

WINPR_ASSERT(s || (n == 0));
if (n == 0)
return NULL;

len = strnlen(s, n);
if (len == n)
len++;

rc = calloc(len, sizeof(char));
if (!rc)
return NULL;
memcpy(rc, s, n);
return rc;
char* dst = calloc(n + 1, sizeof(char));
if (dst)
strncpy(dst, src, n);
return dst;
}
#endif

0 comments on commit bf56a39

Please sign in to comment.