Skip to content

Commit

Permalink
escape: fix error: null destination pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Sep 30, 2024
1 parent 5a46475 commit 3ab5100
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion programs/dwg2SVG.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ output_TEXT (Dwg_Object *obj)
obj->index, transform_X (pt.x), transform_Y (pt.y), fontfamily,
text->height /* fontsize */, entity_color (obj->tio.entity),
escaped ? escaped : "");
free (escaped);
if (escaped)
free (escaped);
}

static void
Expand Down
8 changes: 8 additions & 0 deletions programs/escape.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ htmlescape (const char *restrict src, const Dwg_Codepage cp)
return NULL;
len = strlen (src) + 10;
d = (char *)calloc (len, 1);
if (!d)
return NULL;
s = (unsigned char *)src;
dest = d;
end = dest + len;
Expand Down Expand Up @@ -93,6 +95,8 @@ htmlescape (const char *restrict src, const Dwg_Codepage cp)
wc = dwg_codepage_uwc (cp, cc);
if (wc > 127 || wc < 0x20)
{
if (!d)
return NULL;
sprintf (d, "&#x%X;", (unsigned)wc); // 4 + 4
d += strlen (d);
}
Expand Down Expand Up @@ -123,6 +127,8 @@ htmlwescape (BITCODE_TU wstr)
len++;
len += 16;
d = dest = (char *)calloc (len, 1);
if (!d)
return NULL;

while (*wstr)
{
Expand Down Expand Up @@ -174,6 +180,8 @@ htmlwescape (BITCODE_TU wstr)
default:
if (*wstr >= 127 || *wstr < 20) // utf8 encodings
{
if (!d)
return NULL;
sprintf (d, "&#x%X;", *wstr);
d += strlen (d);
*d = 0;
Expand Down

0 comments on commit 3ab5100

Please sign in to comment.