Skip to content

Commit 7ac0f2b

Browse files
committed
Minor C++ improvements
1 parent c9898ea commit 7ac0f2b

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/cntr.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ slit_cutter (Csite * site, int up, int pass2)
717717

718718
if (up)
719719
{
720+
assert(pass2);
721+
720722
/* upward stroke of slit proceeds up left side of slit until
721723
* it hits a boundary or a point not between the contour levels
722724
* -- this never happens on the first pass */
@@ -1406,7 +1408,11 @@ int reorder(double *xpp, double *ypp, short *kpp,
14061408

14071409
/* Find the subpaths as sets of connected segments. */
14081410

1409-
subp = (int *)malloc(nsegs * sizeof(int));
1411+
if (nsegs) {
1412+
subp = (int *)malloc(nsegs * sizeof(int));
1413+
} else {
1414+
subp = NULL;
1415+
}
14101416
for (i=0; i<nsegs; i++) subp[i] = -1;
14111417

14121418
nsp = 0;
@@ -2025,5 +2031,3 @@ init_cntr(void)
20252031
return m;
20262032
#endif
20272033
}
2028-
2029-

src/ft2font.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,13 @@ void FT2Image::resize(long width, long height)
6868
delete[] m_buffer;
6969
m_buffer = NULL;
7070
m_buffer = new unsigned char[numBytes];
71+
memset(m_buffer, 0, numBytes);
7172
}
7273

7374
m_width = (unsigned long)width;
7475
m_height = (unsigned long)height;
7576
}
7677

77-
if (numBytes) {
78-
memset(m_buffer, 0, numBytes);
79-
}
80-
8178
m_dirty = true;
8279
}
8380

src/numpy_cpp.h

+2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
425425
PyArrayObject *tmp;
426426

427427
if (arr == NULL || arr == Py_None) {
428+
Py_XDECREF(m_arr);
428429
m_arr = NULL;
429430
m_data = NULL;
430431
m_shape = zeros;
@@ -440,6 +441,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
440441
}
441442

442443
if (PyArray_NDIM(tmp) == 0 || PyArray_DIM(tmp, 0) == 0) {
444+
Py_XDECREF(m_arr);
443445
m_arr = NULL;
444446
m_data = NULL;
445447
m_shape = zeros;

src/py_converters.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,14 @@ int convert_offset_position(PyObject *obj, void *offsetp)
493493
e_offset_position *offset = (e_offset_position *)offsetp;
494494
const char *names[] = {"data", NULL};
495495
int values[] = {OFFSET_POSITION_DATA};
496-
int result;
497-
498-
*offset = OFFSET_POSITION_FIGURE;
496+
int result = OFFSET_POSITION_FIGURE;
499497

500-
if (convert_string_enum(obj, "offset_position", names, values, &result)) {
501-
*offset = (e_offset_position)result;
502-
} else {
498+
if (!convert_string_enum(obj, "offset_position", names, values, &result)) {
503499
PyErr_Clear();
504500
}
505501

502+
*offset = result;
503+
506504
return 1;
507505
}
508506

0 commit comments

Comments
 (0)