Skip to content

Commit

Permalink
observe SAFECLIB_ENABLE_UNSAFE
Browse files Browse the repository at this point in the history
hide the UNSAFE functions with --disable-unsafe.

Also resolve the header inclusion loops from #14
  • Loading branch information
rurban committed Sep 1, 2017
1 parent 43373cd commit e996a27
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH = src
INCLUDE_FILE_PATTERNS =
PREDEFINED =
PREDEFINED = HAVE_WCHAR_H SAFECLIB_ENABLE_UNSAFE
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions include/safe_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ extern void ignore_handler_s(const char *restrict msg, void *restrict ptr, errno

#define sl_default_handler ignore_handler_s

#ifndef __SAFE_MEM_LIB_H__
#include "safe_mem_lib.h"
#endif
#ifndef __SAFE_STR_LIB_H__
#include "safe_str_lib.h"
#endif

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions include/safe_mem_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
extern "C" {
#endif

#ifndef __SAFE_LIB_H__
#include "safe_lib.h"
#endif

#define RSIZE_MAX_MEM16 ( RSIZE_MAX_MEM/2 )
#define RSIZE_MAX_MEM32 ( RSIZE_MAX_MEM/4 )
Expand Down
2 changes: 2 additions & 0 deletions include/safe_str_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
extern "C" {
#endif

#ifndef __SAFE_LIB_H__
#include "safe_lib.h"
#endif
#include <stdarg.h>
#ifdef HAVE_WCHAR_H
#include <wchar.h>
Expand Down
8 changes: 5 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ AM_CFLAGS += -Werror -pedantic -Imem -Istr

noinst_LTLIBRARIES = \
libmemprims.la \
libsafeccore.la \
libstdunsafe.la
libsafeccore.la
# libsafecmem.la \
# libsafecstr.la
libmemprims_la_SOURCES = $(MEM_PRIM_FILES)
libsafeccore_la_SOURCES = $(CORE_FILES)
libstdunsafe_la_SOURCES = $(STD_UNSAFE_FILES)
#libsafecmem_la_SOURCES = $(STD_MEM_FILES) $(EXT_MEM_FILES)
#libsafecstr_la_SOURCES = $(STD_STR_FILES) $(EXT_STR_FILES)
if ENABLE_UNSAFE
noinst_LTLIBRARIES += libstdunsafe.la
libstdunsafe_la_SOURCES = $(STD_UNSAFE_FILES)
endif

#EXPORT_SYM = exported.sym
#$(EXPORT_SYM): safec.h.in
Expand Down
7 changes: 6 additions & 1 deletion src/str/snprintf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "config.h"
#include "safe_str_lib.h"
#include "safe_str_constraint.h"
#include <stdarg.h>

#ifdef SAFECLIB_ENABLE_UNSAFE

/* TODO: error when fmt contains %n, or encoding errors occur.
*/
Expand Down Expand Up @@ -89,6 +90,8 @@
*
*/

#include "safeclib_private.h"

int snprintf_s(char * restrict dest, rsize_t dmax, const char * restrict fmt, ...)
{
va_list ap;
Expand Down Expand Up @@ -133,3 +136,5 @@ int snprintf_s(char * restrict dest, rsize_t dmax, const char * restrict fmt, ..

return ret;
}

#endif /* SAFECLIB_ENABLE_UNSAFE */
9 changes: 6 additions & 3 deletions src/str/vsnprintf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
#include "config.h"
#include "safe_str_lib.h"
#include "safe_str_constraint.h"
#include <stdarg.h>

#ifdef SAFECLIB_ENABLE_UNSAFE

/* TODO: error when fmt contains %n, or encoding errors occur.
*/

/**
* @brief
Expand Down Expand Up @@ -87,8 +90,6 @@
*/

#include "safeclib_private.h"
#include "safe_str_constraint.h"
#include "safe_str_lib.h"

int vsnprintf_s(char *restrict dest, rsize_t dmax, const char *restrict fmt, va_list ap)
{
Expand Down Expand Up @@ -129,3 +130,5 @@ int vsnprintf_s(char *restrict dest, rsize_t dmax, const char *restrict fmt, va_

return ret;
}

#endif /* SAFECLIB_ENABLE_UNSAFE */

0 comments on commit e996a27

Please sign in to comment.