[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #62532] libs/libgroff/fontfile.cpp: memory allocation is placed out
From: |
Bjarni Ingi Gislason |
Subject: |
[bug #62532] libs/libgroff/fontfile.cpp: memory allocation is placed outside of a conditional but needs only to be inside it. |
Date: |
Fri, 27 May 2022 17:31:31 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?62532>
Summary: libs/libgroff/fontfile.cpp: memory allocation is
placed outside of a conditional but needs only to be inside it.
Project: GNU troff
Submitted by: bjarniig
Submitted on: Fri 27 May 2022 09:31:29 PM UTC
Category: Core
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Fri 27 May 2022 09:31:29 PM UTC By: Bjarni Ingi Gislason <bjarniig>
Subject: libs/libgroff/fontfile.cpp: memory allocation is placed
outside of a conditional but needs only to be inside it.
Found with "cppcheck".
Part of code:
FILE *font::open_file(const char *nm, char **pathp)
{
FILE *fp = 0;
int expected_size = strlen(nm) + strlen(device) + 5; // 'dev' '/' '\0'
char *filename = new char[expected_size];
// Do not traverse user-specified directories; Savannah #61424.
if (0 == strchr(nm, '/')) {
int actual_size = sprintf(filename, "dev%s/%s", device, nm);
expected_size--; // sprintf() doesn't count the null terminator.
if (actual_size == expected_size)
fp = font_path.open_file(filename, pathp);
}
delete[] filename;
return fp;
}
Only the lines
FILE *fp = 0;
and
return fp;
should be outside the if-conditional, the others are only needed inside
it.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62532>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #62532] libs/libgroff/fontfile.cpp: memory allocation is placed outside of a conditional but needs only to be inside it.,
Bjarni Ingi Gislason <=