diff --git a/CMakeLists.txt b/CMakeLists.txt index de261719f3..9afdd4f65d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,7 @@ endif() if (WCHAR_T EQUAL 2) set(HAVE_PCRE2_16 1) endif() + if (NOT HAVE_MIMALLOC_OVERRIDE_H) if (ENABLE_MIMALLOC) message(WARNING "Should not ENABLE_MIMALLOC without mimalloc-override.h") diff --git a/configure.ac b/configure.ac index e854a7bd2e..e4e001e7b9 100644 --- a/configure.ac +++ b/configure.ac @@ -247,7 +247,7 @@ if test x$enable_shared = xyes && \ then AX_COMPILER_FLAGS([WARN_CFLAGS],[AM_LDFLAGS],[$ax_is_release], [-fno-semantic-interposition -fwrapv -fno-common -fvisibility=hidden \ - -fno-strict-aliasing -ftrivial-auto-var-init=zero \ + -fno-strict-aliasing -ftrivial-auto-var-init=zero -fstrict-flex-arrays=3 \ -fstack-protector-strong -fstack-clash-protection \ -fcf-protection=full -fno-delete-null-pointer-checks \ -Wno-alloc-size]) @@ -283,6 +283,7 @@ AX_GCC_FUNC_ATTRIBUTE(malloc) AX_GCC_FUNC_ATTRIBUTE(returns_nonnull) AX_GCC_FUNC_ATTRIBUTE(noreturn) AX_GCC_FUNC_ATTRIBUTE(aligned) +AX_GCC_FUNC_ATTRIBUTE(counted_by) if test x$ax_cv_check_cflags__Wformat_y2k = xyes || \ test x$ax_cv_check_cflags__Wformat_2__Wformat_y2k = xyes then diff --git a/doc/dynapi.texi b/doc/dynapi.texi index 8d99d0daa6..91c476df2d 100644 --- a/doc/dynapi.texi +++ b/doc/dynapi.texi @@ -13796,10 +13796,10 @@ BD* struct _dwg_object_BLOCKSTRETCHACTION* @item bl95 BL, DXF 95 -@item bs76 +@item num_indexes BS, DXF 76 -@item bl94 -BL, DXF 94 +@item indexes +BL*, DXF 94 @end vtable @end indentedblock @@ -13814,12 +13814,10 @@ BL, DXF 94 struct _dwg_object_BLOCKSTRETCHACTION* @item hdl H, DXF 331 -@item shrt +@item num_indexes BS, DXF 74 -@item long1 -BL, DXF 94 -@item long2 -BL, DXF 94 +@item indexes +BL*, DXF 94 @end vtable @end indentedblock @@ -14481,7 +14479,7 @@ BD, DXF 53 @item num_dashes BS, DXF 79 @item dashes -BD* +BD*, DXF 49 @end vtable @end indentedblock @@ -14561,9 +14559,9 @@ BL, DXF 97 @item fitpts 2RD* @item start_tangent -2RD +2RD, DXF 12 @item end_tangent -2RD +2RD, DXF 13 @end vtable @end indentedblock diff --git a/include/dwg.h b/include/dwg.h index 7ac63f88c2..6ebeb22473 100644 --- a/include/dwg.h +++ b/include/dwg.h @@ -68,6 +68,19 @@ # endif #endif +#ifndef __counted_by +# if (defined(__clang__) && (__clang_major__ >= 18)) || \ + (defined( __GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 1500) +# define __counted_by(x) __attribute__((__counted_by__(x))) +# ifdef __cplusplus +# undef __counted_by +# define __counted_by(x) +# endif +# else +# define __counted_by(x) +# endif +#endif + #ifdef __cplusplus extern "C" { # ifndef restrict @@ -7799,17 +7812,16 @@ typedef struct _dwg_object_BLOCKSCALEACTION typedef struct _dwg_BLOCKSTRETCHACTION_handles { struct _dwg_object_BLOCKSTRETCHACTION *parent; - BITCODE_H hdl; // 331 - BITCODE_BS shrt; // 74 - BITCODE_BL long1; // 94 - BITCODE_BL long2; // 94 + BITCODE_H hdl; // 331 + BITCODE_BS num_indexes; // 74 + BITCODE_BL *indexes; // 94 } Dwg_BLOCKSTRETCHACTION_handles; typedef struct _dwg_BLOCKSTRETCHACTION_codes { struct _dwg_object_BLOCKSTRETCHACTION *parent; - BITCODE_BL bl95; // 95 - BITCODE_BS bs76; // 76 - BITCODE_BL bl94; // 94 + BITCODE_BL bl95; // 95 + BITCODE_BS num_indexes; // 76 + BITCODE_BL *indexes; // 94 } Dwg_BLOCKSTRETCHACTION_codes; typedef struct _dwg_object_BLOCKSTRETCHACTION @@ -7820,7 +7832,7 @@ typedef struct _dwg_object_BLOCKSTRETCHACTION BITCODE_BL num_pts; // 72 BITCODE_2RD *pts; // 10 BITCODE_BL num_hdls; // 72 - Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94, 94 */ + Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94 */ BITCODE_BL num_codes; // 75 Dwg_BLOCKSTRETCHACTION_codes *codes; /*!< DXF 95, 76, 94 */ BLOCKACTION_doubles_fields; @@ -8144,17 +8156,29 @@ typedef struct _dwg_entity_eed_data BITCODE_RS length; /* RC */ unsigned short codepage:15; /* RS_LE */ unsigned short is_tu:1; - char string[1]; /* inlined */ +#ifndef SWIG + char string[] __counted_by(length); /* inlined */ +#else + char string[0]; // swig limitation https://github.com/swig/swig/issues/1699 +#endif } eed_0; struct { /* R2007+ 0 (1000) string */ BITCODE_RS length; unsigned short _padding:15; unsigned short is_tu:1; - DWGCHAR string[1]; /* inlined */ +#ifndef SWIG + DWGCHAR string[] __counted_by(length); /* inlined */ +#else + DWGCHAR string[0]; +#endif } eed_0_r2007; struct { /* 1 (1001) handle, not in data */ - char invalid[1]; // set the eed[0].handle to the used APPID instead BITCODE_RS appid_index; +#ifndef SWIG + char invalid[]; // set the eed[0].handle to the used APPID instead +#else + char invalid[0]; +#endif } eed_1; struct { /* 2 (1002) "{" => 0 open, or "}" => 1 close */ BITCODE_RC close; @@ -8164,7 +8188,7 @@ typedef struct _dwg_entity_eed_data } eed_3; struct { /* 4 (1004) binary */ BITCODE_RC length; - unsigned char data[1]; // inlined + unsigned char data[] __counted_by(length); // inlined } eed_4; struct { /* 5 (1005) entity */ BITCODE_RLL entity; diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4 index 8a05b0c74b..4b9805e313 100644 --- a/m4/ax_gcc_func_attribute.m4 +++ b/m4/ax_gcc_func_attribute.m4 @@ -32,6 +32,7 @@ # const # constructor # constructor_priority for constructor attribute with priority +# counted_by # deprecated # destructor # dllexport @@ -48,7 +49,6 @@ # ifunc # leaf # malloc -# ms_format # noclone # noinline # nonnull @@ -95,6 +95,7 @@ AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ CFLAGS="$CFLAGS -Werror" fi fi + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ AC_LINK_IFELSE([AC_LANG_PROGRAM([ m4_case([$1], @@ -126,6 +127,9 @@ AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ [constructor], [ int foo( void ) __attribute__(($1)); ], + [counted_by], [ + struct { int size; int flex[[]] __attribute__((__counted_by__(size))); } x; + ], [deprecated], [ int foo( void ) __attribute__(($1(""))); ], diff --git a/m4/ax_printf_size_t.m4 b/m4/ax_printf_size_t.m4 index bdd8e4e0e3..333570a764 100644 --- a/m4/ax_printf_size_t.m4 +++ b/m4/ax_printf_size_t.m4 @@ -49,7 +49,7 @@ save_CFLAGS="$CFLAGS" if test "_$GCC" = _yes then # Take advantage of GCC's format-string checking - CFLAGS="$CFLAGS -Wformat -pedantic -Werror" + CFLAGS="$CFLAGS -Wformat -pedantic -Werror -Wno-deprecated" fi result=unknown diff --git a/programs/my_stat.h b/programs/my_stat.h index 7560d316e9..4df879cc32 100644 --- a/programs/my_stat.h +++ b/programs/my_stat.h @@ -37,6 +37,9 @@ int _access (const char *path, int mode); # ifndef S_ISREG # define S_ISREG(m) ((m & 0170000) == _S_IFREG) # endif +# ifndef S_ISDIR +# define S_ISDIR(m) ((m & 0170000) == _S_IFDIR) +# endif # ifndef W_OK # define W_OK 0 # endif diff --git a/src/Makefile.am b/src/Makefile.am index 3f308e355b..a4a31bb019 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -190,7 +190,7 @@ clang-tidy: ../compile_commands.json # emacs flymake-mode check-syntax: test -n "$(CHK_SOURCES)" && \ - nice $(COMPILE) -O0 -o /dev/null -S $(CHK_SOURCES) + nice $(COMPILE) -I. -O0 -o /dev/null -S $(CHK_SOURCES) .PHONY: check-syntax cppcheck clang-tidy if ENABLE_GCOV diff --git a/src/bits.c b/src/bits.c index 62049567c5..e76fece17d 100644 --- a/src/bits.c +++ b/src/bits.c @@ -2070,7 +2070,7 @@ bit_wcs2dup (const BITCODE_TU restrict src) return NULL; len = bit_wcs2len (src); blen = (len + 1) * 2; // include the zero - d = malloc (blen); + d = (BITCODE_TU)malloc (blen); if (d) memcpy (d, src, blen); return d; @@ -2173,12 +2173,12 @@ bit_write_TV (Bit_Chain *restrict dat, BITCODE_TV restrict chain) if (length && dat->opts & DWG_OPTS_INJSON) { size_t destlen = length * 2; - char *dest = malloc (destlen); + char *dest = (char*)malloc (destlen); while (!bit_utf8_to_TV (dest, (unsigned char *)chain, destlen, length, 0, dat->codepage)) { destlen *= 2; - dest = realloc (dest, destlen); + dest = (char*)realloc (dest, destlen); } need_free = true; chain = dest; diff --git a/src/codepages.c b/src/codepages.c index f902d1a074..df261992ed 100644 --- a/src/codepages.c +++ b/src/codepages.c @@ -451,7 +451,7 @@ dwg_codepage_isalnum (const Dwg_Codepage cp, const wchar_t c) const uint8_t key = c & 0xff; const uint8_t sz8 = fntbl[0]; const size_t sz = (size_t)sz8; - uint8_t *found = bsearch (&key, &fntbl[1], sz, 1, b8_cmp); + uint8_t *found = (uint8_t *)bsearch (&key, &fntbl[1], sz, 1, b8_cmp); if (!found || found == &fntbl[0]) return false; else @@ -463,7 +463,7 @@ dwg_codepage_isalnum (const Dwg_Codepage cp, const wchar_t c) const uint16_t *fntbl16 = cp_alnum16tbl[cp]; const uint16_t sz16 = fntbl16[0]; const size_t sz = (size_t)sz16; - uint16_t *found = bsearch (&key, &fntbl16[1], sz, 2, b16_cmp); + uint16_t *found = (uint16_t *)bsearch (&key, &fntbl16[1], sz, 2, b16_cmp); if (!found || found == &fntbl16[0]) return false; else diff --git a/src/common.h b/src/common.h index fdbab17682..5e769df0de 100644 --- a/src/common.h +++ b/src/common.h @@ -392,6 +392,16 @@ EXPORT int strcasecmp (const char *a, const char *b); # define ATTRIBUTE_NORETURN #endif +#ifndef __counted_by +# ifdef HAVE_FUNC_ATTRIBUTE_COUNTED_BY +# define __counted_by(x) __attribute__ ((__counted_by__(x))) +# elif defined(_MSC_VER) +# define __counted_by(x) +# else +# define __counted_by(x) +# endif +#endif + #if defined(_WIN32) && defined(HAVE_FUNC_ATTRIBUTE_MS_FORMAT) \ && !defined(__USE_MINGW_ANSI_STDIO) # define ATTRIBUTE_FORMAT(x, y) __attribute__ ((format (ms_printf, x, y))) diff --git a/src/config.h.in b/src/config.h.in index fe3ca5b163..c177e41df1 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -48,7 +48,7 @@ /* Define if __attribute__((visibility("default"))) is supported. */ #undef HAVE_ATTRIBUTE_VISIBILITY_DEFAULT -/* Define to 1 if you have the `basename' function. */ +/* Define to 1 if you have the 'basename' function. */ #undef HAVE_BASENAME /* Define to 1 if be64toh is available in . */ @@ -81,12 +81,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_FLOAT_H -/* Define to 1 if you have the `floor' function. */ +/* Define to 1 if you have the 'floor' function. */ #undef HAVE_FLOOR /* Define to 1 if the system has the `aligned' function attribute */ #undef HAVE_FUNC_ATTRIBUTE_ALIGNED +/* Define to 1 if the system has the `counted_by' function attribute */ +#undef HAVE_FUNC_ATTRIBUTE_COUNTED_BY + /* Define to 1 if the system has the `format' function attribute */ #undef HAVE_FUNC_ATTRIBUTE_FORMAT @@ -108,13 +111,13 @@ /* Define to 1 if you have the header file. */ #undef HAVE_GETOPT_H -/* Define to 1 if you have the `getopt_long' function. */ +/* Define to 1 if you have the 'getopt_long' function. */ #undef HAVE_GETOPT_LONG -/* Define to 1 if you have the `gettimeofday' function. */ +/* Define to 1 if you have the 'gettimeofday' function. */ #undef HAVE_GETTIMEOFDAY -/* Define to 1 if you have the `gmtime_r' function. */ +/* Define to 1 if you have the 'gmtime_r' function. */ #undef HAVE_GMTIME_R /* macOS 12.6.5 lies about its gperf version, using size_t as 3.0 */ @@ -156,7 +159,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LIBGEN_H -/* Define to 1 if you have the `m' library (-lm). */ +/* Define to 1 if you have the 'm' library (-lm). */ #undef HAVE_LIBM /* Define to 1 if you have the header file. */ @@ -168,20 +171,20 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MACHINE_ENDIAN_H -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and +/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and to 0 otherwise. */ #undef HAVE_MALLOC /* Define to 1 if you have the header file. */ #undef HAVE_MALLOC_H -/* Define to 1 if you have the `memchr' function. */ +/* Define to 1 if you have the 'memchr' function. */ #undef HAVE_MEMCHR -/* Define to 1 if you have the `memmem' function. */ +/* Define to 1 if you have the 'memmem' function. */ #undef HAVE_MEMMEM -/* Define to 1 if you have the `memmove' function. */ +/* Define to 1 if you have the 'memmove' function. */ #undef HAVE_MEMMOVE /* Define to 1 if you have the header file. */ @@ -196,26 +199,26 @@ /* If available, contains the Python version number currently in use. */ #undef HAVE_PYTHON -/* Define to 1 if your system has a GNU libc compatible `realloc' function, +/* Define to 1 if your system has a GNU libc compatible 'realloc' function, and to 0 otherwise. */ #undef HAVE_REALLOC -/* Define to 1 if you have the `scandir' function. */ +/* Define to 1 if you have the 'scandir' function. */ #undef HAVE_SCANDIR -/* Define to 1 if you have the `setenv' function. */ +/* Define to 1 if you have the 'setenv' function. */ #undef HAVE_SETENV -/* Define to 1 if you have the `sincos' function. */ +/* Define to 1 if you have the 'sincos' function. */ #undef HAVE_SINCOS -/* Define to 1 if you have the `sqrt' function. */ +/* Define to 1 if you have the 'sqrt' function. */ #undef HAVE_SQRT -/* Define to 1 if you have the `sscanf_s' function. */ +/* Define to 1 if you have the 'sscanf_s' function. */ #undef HAVE_SSCANF_S -/* Define to 1 if `stat' has the bug that it succeeds when given the +/* Define to 1 if 'stat' has the bug that it succeeds when given the zero-length file name argument. */ #undef HAVE_STAT_EMPTY_STRING_BUG @@ -231,13 +234,13 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H -/* Define to 1 if you have the `strcasecmp' function. */ +/* Define to 1 if you have the 'strcasecmp' function. */ #undef HAVE_STRCASECMP -/* Define to 1 if you have the `strcasestr' function. */ +/* Define to 1 if you have the 'strcasestr' function. */ #undef HAVE_STRCASESTR -/* Define to 1 if you have the `strchr' function. */ +/* Define to 1 if you have the 'strchr' function. */ #undef HAVE_STRCHR /* Define to 1 if you have the header file. */ @@ -246,25 +249,25 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H -/* Define to 1 if you have the `strnlen' function. */ +/* Define to 1 if you have the 'strnlen' function. */ #undef HAVE_STRNLEN -/* Define to 1 if you have the `strrchr' function. */ +/* Define to 1 if you have the 'strrchr' function. */ #undef HAVE_STRRCHR -/* Define to 1 if you have the `strstr' function. */ +/* Define to 1 if you have the 'strstr' function. */ #undef HAVE_STRSTR -/* Define to 1 if you have the `strtol' function. */ +/* Define to 1 if you have the 'strtol' function. */ #undef HAVE_STRTOL -/* Define to 1 if you have the `strtoll' function. */ +/* Define to 1 if you have the 'strtoll' function. */ #undef HAVE_STRTOLL -/* Define to 1 if you have the `strtoul' function. */ +/* Define to 1 if you have the 'strtoul' function. */ #undef HAVE_STRTOUL -/* Define to 1 if you have the `strtoull' function. */ +/* Define to 1 if you have the 'strtoull' function. */ #undef HAVE_STRTOULL /* Define to 1 if you have the header file. */ @@ -294,19 +297,19 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WCHAR_H -/* Define to 1 if you have the `wcscmp' function. */ +/* Define to 1 if you have the 'wcscmp' function. */ #undef HAVE_WCSCMP -/* Define to 1 if you have the `wcscpy' function. */ +/* Define to 1 if you have the 'wcscpy' function. */ #undef HAVE_WCSCPY -/* Define to 1 if you have the `wcslen' function. */ +/* Define to 1 if you have the 'wcslen' function. */ #undef HAVE_WCSLEN -/* Define to 1 if you have the `wcsnlen' function. */ +/* Define to 1 if you have the 'wcsnlen' function. */ #undef HAVE_WCSNLEN -/* Define to 1 if you have the `wcsstr' function. */ +/* Define to 1 if you have the 'wcsstr' function. */ #undef HAVE_WCSSTR /* Define to 1 if you have the header file. */ @@ -321,7 +324,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WINSOCK2_H -/* Define to 1 if the system has the type `_Bool'. */ +/* Define to 1 if the system has the type '_Bool'. */ #undef HAVE__BOOL /* Define as const if the declaration of iconv() needs const. */ @@ -331,7 +334,7 @@ DWG versions and objects. */ #undef IS_RELEASE -/* Define to 1 if `lstat' dereferences a symlink specified with a trailing +/* Define to 1 if 'lstat' dereferences a symlink specified with a trailing slash. */ #undef LSTAT_FOLLOWS_SLASHED_SYMLINK @@ -359,7 +362,7 @@ /* Define to the printf() modifier to use with size_t. */ #undef PRI_SIZE_T_MODIFIER -/* The size of `size_t', as computed by sizeof. */ +/* The size of 'size_t', as computed by sizeof. */ #undef SIZEOF_SIZE_T /* The number of bytes in type wchar_t */ @@ -373,7 +376,7 @@ STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION -/* Define to 1 if all of the C90 standard headers exist (not just the ones +/* Define to 1 if all of the C89 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ #undef STDC_HEADERS @@ -412,7 +415,7 @@ /* Needed for cygwin strdup */ #undef __XSI_VISIBLE -/* Define to `__inline__' or `__inline' if that's what the C compiler +/* Define to '__inline__' or '__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus #undef inline @@ -439,7 +442,7 @@ /* If restrict is broken with this C compiler */ #undef restrict -/* Define to `unsigned int' if does not define. */ +/* Define as 'unsigned int' if doesn't define. */ #undef size_t /* Define to the type of an unsigned integer type of width exactly 16 bits if diff --git a/src/decode.c b/src/decode.c index 740b9508b1..bbce86eac2 100644 --- a/src/decode.c +++ b/src/decode.c @@ -2590,7 +2590,13 @@ secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg) Bit_Chain *str_dat = dat; Dwg_SecondHeader *_obj = &dwg->secondheader; // for error logging only: +#ifndef __cplusplus Dwg_Object *obj = &(Dwg_Object){ .name = (char *)"2NDHEADER" }; +#else + Dwg_Object xobj; + xobj.name = (char *)"2NDHEADER"; + Dwg_Object *obj = &xobj; +#endif int error = 0; BITCODE_BL vcount; if (!dat->chain || !dat->size) diff --git a/src/dwg.spec b/src/dwg.spec index 5a3723b657..6504897a30 100644 --- a/src/dwg.spec +++ b/src/dwg.spec @@ -5134,11 +5134,13 @@ DWG_ENTITY (HATCH) END_REPEAT_BLOCK END_REPEAT (control_points); #undef control_points - SINCE (R_2013) // r2014 really + SINCE (R_2010) { #define seg segx[rcount2] SUB_FIELD_BL (seg, num_fitpts, 97); FIELD_2RD_VECTOR (seg.fitpts, seg.num_fitpts, 11); + SUB_FIELD_2RD (seg, start_tangent, 12); + SUB_FIELD_2RD (seg, end_tangent, 13); } break; default: @@ -12425,13 +12427,8 @@ DWG_OBJECT (BLOCKSTRETCHACTION) REPEAT (num_hdls, hdls, Dwg_BLOCKSTRETCHACTION_handles) REPEAT_BLOCK SUB_FIELD_HANDLE (hdls[rcount1], hdl, 0, 331); - SUB_FIELD_BS (hdls[rcount1], shrt, 74); - SUB_FIELD_BL (hdls[rcount1], long1, 94); - // See GRUE_LTM_1090+_from_cadforum.cz_2018 - if (FIELD_VALUE (hdls[rcount1].long1) >= 128) { - DEBUG_HERE_OBJ - } - SUB_FIELD_BL (hdls[rcount1], long2, 94); + SUB_FIELD_BS (hdls[rcount1], num_indexes, 74); + SUB_FIELD_VECTOR (hdls[rcount1], indexes, BL, num_indexes, 94); SET_PARENT_OBJ (hdls[rcount1]); END_REPEAT_BLOCK END_REPEAT (hdls) @@ -12439,8 +12436,8 @@ DWG_OBJECT (BLOCKSTRETCHACTION) REPEAT (num_codes, codes, Dwg_BLOCKSTRETCHACTION_codes) REPEAT_BLOCK SUB_FIELD_BL (codes[rcount1], bl95, 95); - SUB_FIELD_BS (codes[rcount1], bs76, 76); - SUB_FIELD_BL (codes[rcount1], bl94, 94); + SUB_FIELD_BS (codes[rcount1], num_indexes, 76); + SUB_FIELD_VECTOR (codes[rcount1], indexes, BL, num_indexes, 94); SET_PARENT_OBJ (codes[rcount1]); END_REPEAT_BLOCK END_REPEAT (codes) diff --git a/src/dwg_api.c b/src/dwg_api.c index 609a596d31..70aeedbbad 100644 --- a/src/dwg_api.c +++ b/src/dwg_api.c @@ -22000,7 +22000,7 @@ EXPORT bool dwg_is_valid_name_u8 (Dwg_Data *restrict dwg, const char *restrict name) { Dwg_Version_Type version = dwg->header.version; - const Dwg_Codepage cp = dwg->header.codepage; + const Dwg_Codepage cp = (const Dwg_Codepage)dwg->header.codepage; BITCODE_TU wstr; size_t wlen; #ifndef HAVE_NONNULL @@ -22067,7 +22067,7 @@ EXPORT bool dwg_is_valid_name (Dwg_Data *restrict dwg, const char *restrict name) { Dwg_Version_Type version = dwg->header.version; - const Dwg_Codepage cp = dwg->header.codepage; + const Dwg_Codepage cp = (const Dwg_Codepage)dwg->header.codepage; #ifndef HAVE_NONNULL if (!name) return false; diff --git a/src/dynapi.c b/src/dynapi.c index a4cc1743c8..5c4413862b 100644 --- a/src/dynapi.c +++ b/src/dynapi.c @@ -11242,10 +11242,10 @@ static const Dwg_DYNAPI_field _dwg_BLOCKSTRETCHACTION_codes_fields[] = { 1,1,0, 0 }, { "bl95", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_BLOCKSTRETCHACTION_codes, bl95), 0,0,0, 95 }, - { "bs76", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_codes, bs76), + { "num_indexes", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_codes, num_indexes), 0,0,0, 76 }, - { "bl94", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_BLOCKSTRETCHACTION_codes, bl94), - 0,0,0, 94 }, + { "indexes", "BL*", sizeof (BITCODE_BL*), OFF (struct _dwg_BLOCKSTRETCHACTION_codes, indexes), + 1,1,0, 94 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_BLOCKSTRETCHACTION_handles: (sorted by offset) */ @@ -11254,12 +11254,10 @@ static const Dwg_DYNAPI_field _dwg_BLOCKSTRETCHACTION_handles_fields[] = { 1,1,0, 0 }, { "hdl", "H", sizeof (BITCODE_H), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, hdl), 1,0,0, 331 }, - { "shrt", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, shrt), + { "num_indexes", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, num_indexes), 0,0,0, 74 }, - { "long1", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, long1), - 0,0,0, 94 }, - { "long2", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, long2), - 0,0,0, 94 }, + { "indexes", "BL*", sizeof (BITCODE_BL*), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, indexes), + 1,1,0, 94 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_BLOCKVISIBILITYPARAMETER_state: (sorted by offset) */ @@ -11753,7 +11751,7 @@ static const Dwg_DYNAPI_field _dwg_HATCH_DefLine_fields[] = { { "num_dashes", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_HATCH_DefLine, num_dashes), 0,0,0, 79 }, { "dashes", "BD*", sizeof (BITCODE_BD*), OFF (struct _dwg_HATCH_DefLine, dashes), - 1,1,0, 0 }, + 1,1,0, 49 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_HATCH_Path: (sorted by offset) */ @@ -11821,9 +11819,9 @@ static const Dwg_DYNAPI_field _dwg_HATCH_PathSeg_fields[] = { { "fitpts", "2RD*", sizeof (BITCODE_2RD*), OFF (struct _dwg_HATCH_PathSeg, fitpts), 1,1,0, 0 }, { "start_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, start_tangent), - 1,0,0, 0 }, + 1,0,0, 12 }, { "end_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, end_tangent), - 1,0,0, 0 }, + 1,0,0, 13 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_HATCH_PolylinePath: (sorted by offset) */ diff --git a/src/encode.c b/src/encode.c index a1ed37772d..6d1bc7540d 100644 --- a/src/encode.c +++ b/src/encode.c @@ -89,7 +89,11 @@ static BITCODE_BL rcount1 = 0, rcount2 = 0; SECTION_R13_SIZE is the size and the sentinel. */ #define SECTION_R13_SIZE 7U -static Dwg_Section_Type_r13 section_order[SECTION_R13_SIZE] = { 0 }; +static Dwg_Section_Type_r13 section_order[SECTION_R13_SIZE] +#ifndef __cplusplus + = { 0 } +#endif + ; #ifdef USE_TRACING /* This flag means we have checked the environment variable @@ -2083,7 +2087,7 @@ section_remove (Dwg_Section_Type_r13 *psection_order, BITCODE_RL *pnum, (*pnum)--; memmove (&psection_order[i], &psection_order[i + 1], (*pnum - i) * sizeof (Dwg_Section_Type_r13)); - psection_order[*pnum] = SECTION_R13_SIZE; // sentinel (invalid) + psection_order[*pnum] = (Dwg_Section_Type_r13)SECTION_R13_SIZE; // sentinel (invalid) return 1; } @@ -2247,7 +2251,7 @@ encode_check_num_sections (Dwg_Section_Type_r11 id, Dwg_Data *restrict dwg) num_sections = dwg->header.num_sections + 2; if (!id) { - id = num_sections; + id = (Dwg_Section_Type_r11)num_sections; dwg->header.sections = dwg->header.num_sections; } if ((BITCODE_RL)id >= num_sections) @@ -2481,7 +2485,13 @@ encode_secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg) Bit_Chain *str_dat = dat; Dwg_SecondHeader *_obj = &dwg->secondheader; // for error logging only: +#ifndef __cplusplus Dwg_Object *obj = &(Dwg_Object){ .name = (char *)"2NDHEADER" }; +#else + Dwg_Object xobj; + xobj.name = (char *)"2NDHEADER"; + Dwg_Object *obj = &xobj; +#endif int error = 0; BITCODE_BL vcount; if (!dat->chain || !dat->size) @@ -3539,7 +3549,7 @@ dwg_encode (Dwg_Data *restrict dwg, Bit_Chain *restrict dat) // patch all the section tbl->address addr = dwg->header.entities_end + (dat->version >= R_11 ? 0x20 : 0); - encode_check_num_sections (dwg->header.num_sections, dwg); + encode_check_num_sections ((Dwg_Section_Type_r11)dwg->header.num_sections, dwg); if (dwg->header.from_version >= R_13b1) { /* r2000 has e.g. @@ -3893,8 +3903,7 @@ dwg_encode (Dwg_Data *restrict dwg, Bit_Chain *restrict dat) } VERSIONS (R_13b1, R_2000) { - for (Dwg_Section_Type_r13 id = 0; - (unsigned)id < (unsigned)dwg->header.num_sections; id++) + for (unsigned id = 0; id < dwg->header.num_sections; id++) { switch (section_order[id]) { @@ -6690,13 +6699,13 @@ dwg_encode_xdata (Bit_Chain *restrict dat, Dwg_Object_XRECORD *restrict _obj, if (rbuf->value.str.size > 0 && dat->opts & DWG_OPTS_INJSON) { BITCODE_RS destlen = rbuf->value.str.size * 2; - char *dest = malloc (destlen); + char *dest = (char *)malloc (destlen); while (!bit_utf8_to_TV ( dest, (BITCODE_TF)rbuf->value.str.u.data, destlen, rbuf->value.str.size, 0, rbuf->value.str.codepage)) { destlen *= 2; - dest = realloc (dest, destlen); + dest = (char *)realloc (dest, destlen); } destlen = (BITCODE_RS)strlen (dest); bit_write_RS (dat, destlen); @@ -7756,7 +7765,7 @@ dwg_convert_LTYPE_strings_area (const Dwg_Data *restrict dwg, _obj->has_strings_area = 0; return; } - _obj->strings_area = calloc (1, 512); + _obj->strings_area = (BITCODE_TF)calloc (1, 512); if (!_obj->strings_area) { _obj->has_strings_area = 0; @@ -7776,7 +7785,7 @@ dwg_convert_LTYPE_strings_area (const Dwg_Data *restrict dwg, BITCODE_TF old = _obj->strings_area; if (!old) _obj->has_strings_area = 0; - _obj->strings_area = calloc (1, 256); + _obj->strings_area = (BITCODE_TF)calloc (1, 256); if (!_obj->strings_area || !old) { // all empty if (old) diff --git a/src/free.c b/src/free.c index 91be1d79c3..02a11050e0 100644 --- a/src/free.c +++ b/src/free.c @@ -682,6 +682,8 @@ free_preR13_object (Dwg_Object *obj) { Dwg_Object_Entity *_obj = obj->tio.entity; FIELD_HANDLE (layer, 2, 8); + if (_obj->layer == NULL || !_obj->layer->handleref.is_global) + return; if (_obj->flag_r11 & FLAG_R11_HAS_LTYPE) // 2 FIELD_HANDLE (ltype, 1, 6); if (_obj->flag_r11 & FLAG_R11_HAS_HANDLING) diff --git a/src/gen-dynapi.pl b/src/gen-dynapi.pl index a7450ef18a..d5cba242ab 100755 --- a/src/gen-dynapi.pl +++ b/src/gen-dynapi.pl @@ -387,6 +387,10 @@ sub dxf_in { my $type = $1; $f = $1; $DXF{$n}->{$f} = $2 if $2; + } elsif (@old && /^\s+SUB_FIELD_VECTOR\s*\($v,\s*(\w+),\s*\w+,\s*\w+,\s*(\d+)\)/) { + my $type = $1; + $f = $1; + $DXF{$n}->{$f} = $2 if $2; } elsif (@old && /^\s+SUB_FIELD_(.+?)\s*\($v,\s*(\w+),\s*(\d+)\)/) { my $type = $1; $f = $2; diff --git a/src/in_dxf.c b/src/in_dxf.c index 8f2670d182..3ab06269a9 100644 --- a/src/in_dxf.c +++ b/src/in_dxf.c @@ -7867,25 +7867,25 @@ add_AcDbBlockStretchAction (Dwg_Object *restrict obj, Bit_Chain *restrict dat) dxf_free_pair (pair); pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->hdls[i].shrt, 74); - o->hdls[i].shrt = pair->value.i; - LOG_TRACE ("%s.hdls[%d].shrt = %u [BS 74]\n", obj->name, i, - (unsigned)o->hdls[i].shrt); + EXPECT_DXF (obj->name, o->hdls[i].num_indexes, 74); + o->hdls[i].num_indexes = pair->value.i; + LOG_TRACE ("%s.hdls[%d].num_indexes = %u [BS 74]\n", obj->name, i, + (unsigned)o->hdls[i].num_indexes); dxf_free_pair (pair); - pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->hdls[i].long1, 94); - o->hdls[i].long1 = pair->value.u; - LOG_TRACE ("%s.hdls[%d].long1 = %u [BL 94]\n", obj->name, i, - (unsigned)o->hdls[i].long1); - dxf_free_pair (pair); + if (o->hdls[i].num_indexes) + { + for (unsigned j = 0; j < o->hdls[i].num_indexes; j++) + { + pair = dxf_read_pair (dat); + EXPECT_DXF (obj->name, o->hdls[i].indexes[j], 94); + o->hdls[i].indexes[j] = pair->value.u; + LOG_TRACE ("%s.hdls[%d].indexes[%d] = %u [BL 94]\n", obj->name, i, j, + (unsigned)o->hdls[i].indexes[j]); + dxf_free_pair (pair); + } + } - pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->hdls[i].long2, 94); - o->hdls[i].long2 = pair->value.u; - LOG_TRACE ("%s.hdls[%d].long2 = %u [BL 94]\n", obj->name, i, - (unsigned)o->hdls[i].long2); - dxf_free_pair (pair); } } @@ -7906,18 +7906,24 @@ add_AcDbBlockStretchAction (Dwg_Object *restrict obj, Bit_Chain *restrict dat) dxf_free_pair (pair); pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->codes[i].bs76, 76); - o->codes[i].bs76 = pair->value.i; - LOG_TRACE ("%s.codes[%d].bs76 = %d [BS 76]\n", obj->name, i, - o->codes[i].bs76); + EXPECT_DXF (obj->name, o->codes[i].num_indexes, 76); + o->codes[i].num_indexes = pair->value.i; + LOG_TRACE ("%s.codes[%d].num_indexes = %d [BS 76]\n", obj->name, i, + o->codes[i].num_indexes); dxf_free_pair (pair); - pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->codes[i].bl94, 94); - o->codes[i].bl94 = pair->value.i; - LOG_TRACE ("%s.codes[%d].bl94 = %d [BL 94]\n", obj->name, i, - o->codes[i].bl94); - dxf_free_pair (pair); + if (o->codes[i].num_indexes) + { + for (unsigned j = 0; j < o->hdls[i].num_indexes; j++) + { + pair = dxf_read_pair (dat); + EXPECT_DXF (obj->name, o->codes[i].indexes[j], 94); + o->codes[i].indexes[j] = pair->value.i; + LOG_TRACE ("%s.codes[%d].indexes[%d] = %d [BL 94]\n", obj->name, i, j, + o->codes[i].indexes[j]); + dxf_free_pair (pair); + } + } } } diff --git a/src/in_json.c b/src/in_json.c index 3145f86d50..1ff6b01c34 100644 --- a/src/in_json.c +++ b/src/in_json.c @@ -3170,6 +3170,7 @@ json_OBJECTS (Bit_Chain *restrict dat, Dwg_Data *restrict dwg, objsize); obj->tio.object = (Dwg_Object_Object *)calloc ( 1, sizeof (Dwg_Object_Object)); + obj->tio.entity = (Dwg_Object_Entity *)calloc(1, sizeof(Dwg_Object_Entity)); obj->tio.object->dwg = dwg; obj->tio.object->objid = i; // NEW_OBJECT (dwg, obj) diff --git a/test/unit-testing/blockstretchaction.c b/test/unit-testing/blockstretchaction.c index 6b1ffc9b98..5f0f39e552 100644 --- a/test/unit-testing/blockstretchaction.c +++ b/test/unit-testing/blockstretchaction.c @@ -6,7 +6,7 @@ void api_process (dwg_object *obj) { int error, isnew; - BITCODE_BL i; + BITCODE_BL i, j; BLOCKACTION_fields; BITCODE_BL num_pts; BITCODE_2RD *pts; @@ -40,16 +40,15 @@ api_process (dwg_object *obj) for (i = 0; i < num_hdls; i++) { CHK_SUBCLASS_H (_obj->hdls[i], BLOCKSTRETCHACTION_handles, hdl); - CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, shrt, BS); - CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, long1, BL); - CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, long2, BL); + CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, num_indexes, BS); + CHK_SUBCLASS_VECTOR_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, indexes, _obj->hdls[i].num_indexes, BL); } CHK_ENTITY_TYPE (_obj, BLOCKSTRETCHACTION, num_codes, BL); for (i = 0; i < num_codes; i++) { CHK_SUBCLASS_TYPE (_obj->codes[i], BLOCKSTRETCHACTION_codes, bl95, BL); - CHK_SUBCLASS_TYPE (_obj->codes[i], BLOCKSTRETCHACTION_codes, bs76, BS); - CHK_SUBCLASS_TYPE (_obj->codes[i], BLOCKSTRETCHACTION_codes, bl94, BL); + CHK_SUBCLASS_TYPE (_obj->codes[i], BLOCKSTRETCHACTION_codes, num_indexes, BS); + CHK_SUBCLASS_VECTOR_TYPE (_obj->codes[i], BLOCKSTRETCHACTION_codes, indexes, _obj->codes[i].num_indexes, BL); } CHK_ENTITY_TYPE (_obj, BLOCKSTRETCHACTION, action_offset_x, BD); diff --git a/test/unit-testing/common.c b/test/unit-testing/common.c index c061273eb1..4406f55ada 100644 --- a/test/unit-testing/common.c +++ b/test/unit-testing/common.c @@ -183,9 +183,9 @@ main (int argc, char *argv[]) if (stat (*ptr, &attrib)) { char tmp[80]; - strcpy (tmp, prefix); - strcat (tmp, "/"); - strcat (tmp, *ptr); + strncpy (tmp, prefix, sizeof (tmp)); + strncat (tmp, "/", sizeof (prefix) - 1); + strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1); if (stat (tmp, &attrib)) fprintf (stderr, "Env var INPUT not defined, %s not found\n", tmp); diff --git a/test/unit-testing/dynapi_test.c b/test/unit-testing/dynapi_test.c index d627b1d264..319fcbe3af 100644 --- a/test/unit-testing/dynapi_test.c +++ b/test/unit-testing/dynapi_test.c @@ -20,8 +20,13 @@ #include #include #include - #include "config.h" +#ifdef __APPLE__ +# define _DARWIN_C_SOURCE /* for DT_DIR */ +#endif +#ifdef HAVE_DIRENT_H +# include +#endif #ifdef HAVE_UNISTD_H # include #endif @@ -45,7 +50,7 @@ test_header (Dwg_Data *dwg) BITCODE_BD bd; BITCODE_TV tv; -#line 46 "dynapi_test.c" +#line 53 "dynapi_test.c" /* @@for test_HEADER@@ */ { BITCODE_RL size; @@ -6095,10 +6100,10 @@ test_header (Dwg_Data *dwg) dwg_dynapi_header_set_value (dwg, "aspect_ratio", &aspect_ratio, 0); } -#line 47 "dynapi_test.c.in" +#line 54 "dynapi_test.c.in" return error; } -#line 5379 "dynapi_test.c" +#line 6106 "dynapi_test.c" /* @@for test_OBJECT@@ */ static int test__3DFACE (const Dwg_Object *obj) { @@ -63780,12 +63785,12 @@ static int test_ASSOCARRAYRECTANGULARPARAMETERS (const Dwg_Object *obj) return failed; } -#line 53 "dynapi_test.c.in" +#line 60 "dynapi_test.c.in" static int test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj) { int error = 0; -#line 62158 "dynapi_test.c" +#line 63793 "dynapi_test.c" /* @@for if_test_OBJECT@@ */ if (obj->fixedtype == DWG_TYPE__3DFACE) error += test__3DFACE(obj); @@ -65047,7 +65052,7 @@ test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj) error += test_ASSOCARRAYPOLARPARAMETERS (obj); else if (obj->fixedtype == DWG_TYPE_ASSOCARRAYRECTANGULARPARAMETERS) error += test_ASSOCARRAYRECTANGULARPARAMETERS (obj); -#line 60 "dynapi_test.c.in" +#line 67 "dynapi_test.c.in" return error + failed; } @@ -65057,7 +65062,7 @@ test_sizes (void) { int error = 0; int size1, size2; -#line 63386 "dynapi_test.c" +#line 65065 "dynapi_test.c" /* @@for test_SIZES@@ */ size1 = sizeof (Dwg_Entity__3DFACE); size2 = dwg_dynapi_fields_size ("3DFACE"); @@ -68611,7 +68616,7 @@ test_sizes (void) "dwg_dynapi_fields_size (\"MLEADER_Content\"): %d\n", size1, size2); error++; } -#line 72 "dynapi_test.c.in" +#line 79 "dynapi_test.c.in" return error; } @@ -68684,10 +68689,20 @@ main (int argc, char *argv[]) if (stat (*ptr, &attrib)) { char tmp[80]; - strncpy (tmp, "../test-data/", sizeof (tmp)); - strncat (tmp, *ptr, sizeof (tmp) - sizeof ("../test-data/") - 1); - if (stat (tmp, &attrib)) - LOG_ERROR ("Env var INPUT not defined, %s not found", tmp) + const char *prefix = "../test-data/"; + strcpy (tmp, prefix); + strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1); + if (stat (tmp, &attrib)) { + /* file not found. try srcdir */ + prefix = "../../../test/test-data/"; + if (!stat (prefix, &attrib) && S_ISDIR (attrib.st_mode)) { + strcpy (tmp, prefix); + strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1); + error += test_dynapi (tmp); + } else { + LOG_ERROR ("Env var INPUT not defined, %s not found", tmp); + } + } else error += test_dynapi (tmp); } diff --git a/test/unit-testing/dynapi_test.c.in b/test/unit-testing/dynapi_test.c.in index c45a055bfb..4e21ad3038 100644 --- a/test/unit-testing/dynapi_test.c.in +++ b/test/unit-testing/dynapi_test.c.in @@ -19,8 +19,13 @@ #include #include #include - #include "config.h" +#ifdef __APPLE__ +# define _DARWIN_C_SOURCE /* for DT_DIR */ +#endif +#ifdef HAVE_DIRENT_H +# include +#endif #ifdef HAVE_UNISTD_H # include #endif @@ -44,22 +49,22 @@ test_header (Dwg_Data *dwg) BITCODE_BD bd; BITCODE_TV tv; -#line 46 "dynapi_test.c" +#line 53 "dynapi_test.c" /* @@for test_HEADER@@ */ -#line 47 "dynapi_test.c.in" +#line 54 "dynapi_test.c.in" return error; } -#line 5379 "dynapi_test.c" +#line 6106 "dynapi_test.c" /* @@for test_OBJECT@@ */ -#line 53 "dynapi_test.c.in" +#line 60 "dynapi_test.c.in" static int test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj) { int error = 0; -#line 62158 "dynapi_test.c" +#line 63793 "dynapi_test.c" /* @@for if_test_OBJECT@@ */ -#line 60 "dynapi_test.c.in" +#line 67 "dynapi_test.c.in" return error + failed; } @@ -69,9 +74,9 @@ test_sizes (void) { int error = 0; int size1, size2; -#line 63386 "dynapi_test.c" +#line 65065 "dynapi_test.c" /* @@for test_SIZES@@ */ -#line 72 "dynapi_test.c.in" +#line 79 "dynapi_test.c.in" return error; } @@ -144,10 +149,20 @@ main (int argc, char *argv[]) if (stat (*ptr, &attrib)) { char tmp[80]; - strncpy (tmp, "../test-data/", sizeof (tmp)); - strncat (tmp, *ptr, sizeof (tmp) - sizeof ("../test-data/") - 1); - if (stat (tmp, &attrib)) - LOG_ERROR ("Env var INPUT not defined, %s not found", tmp) + const char *prefix = "../test-data/"; + strcpy (tmp, prefix); + strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1); + if (stat (tmp, &attrib)) { + /* file not found. try srcdir */ + prefix = "../../../test/test-data/"; + if (!stat (prefix, &attrib) && S_ISDIR (attrib.st_mode)) { + strcpy (tmp, prefix); + strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1); + error += test_dynapi (tmp); + } else { + LOG_ERROR ("Env var INPUT not defined, %s not found", tmp); + } + } else error += test_dynapi (tmp); }