Skip to content

Commit

Permalink
Merge pull request #404 from LLNL/rc2dev-mcm86-23aug24-pystrlist-fuzz…
Browse files Browse the repository at this point in the history
…test

Fix fuzz test case and python strlists
  • Loading branch information
markcmiller86 authored Aug 24, 2024
2 parents ba9a361 + c4ab3c5 commit 58f221b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pdb/pdlow.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ _lite_PD_rd_chrt (PDBfile *file) {
*/
chrt_sz = file->symtaddr - file->chrtaddr + 1;
_lite_PD_tbuffer = MAKE_N(char, chrt_sz);
if (chrt_sz <= 0) return(FALSE);
if (io_read(_lite_PD_tbuffer, 1, chrt_sz, fp) != chrt_sz) return(FALSE);
_lite_PD_tbuffer[chrt_sz-1] = (char) EOF;

Expand Down
13 changes: 11 additions & 2 deletions tools/python/pydbfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ static PyObject *DBfile_DBGetToc(PyObject *self, PyObject *args)
// construct is used for *both* string valued members and variable
// members whose value is also a string but is the name of another dataset
// in the file.
//
// Mark C. Miller, Thu Aug 22 00:34:52 PDT 2024
// Skip possible empty first and last strings in a string list.
// ****************************************************************************
static PyObject *DBfile_DBGetVar(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -199,13 +202,19 @@ static PyObject *DBfile_DBGetVar(PyObject *self, PyObject *args)
char **strArr = DBStringListToStringArray((char*)var, &narr, 0);
if (narr > 0 && strArr)
{
tmp = PyTuple_New(narr);
PyObject *tmp2 = PyList_New(0);
for (int i = 0; i < narr; i++)
{
PyTuple_SET_ITEM(tmp, i, PyString_FromString(strArr[i]));
if (i == 0 && strArr[i] && strArr[i][0] == '\0')
continue; // skip an empty first entry
if (i == (narr-1) && strArr[i] && strArr[i][0] == '\0')
continue; // skip an empty last entry
PyList_Append(tmp2, PyString_FromString(strArr[i]));
FREE(strArr[i]);
}
FREE(strArr);
tmp = PyList_AsTuple(tmp2);
Py_DECREF(tmp2);
}
else
{
Expand Down

0 comments on commit 58f221b

Please sign in to comment.