Skip to content

Commit

Permalink
fix more C++ regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Dec 1, 2024
1 parent 1ffd132 commit 6cdff16
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/codepages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/dwg_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 19 additions & 10 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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])
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 6cdff16

Please sign in to comment.