From 28224bd75ea09860285288add0a662af6aa43dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 31 Mar 2020 10:49:50 +0200 Subject: [PATCH] [python] matplotlib: fix hist implementation This fixes the following crash: input 'hist([1,2,100],[1,2]) on a Python console with matplotlib.pyplot imported --- .../port/mod/matplotlib/pyplot/modpyplot.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/python/port/mod/matplotlib/pyplot/modpyplot.cpp b/python/port/mod/matplotlib/pyplot/modpyplot.cpp index 0cc1005d6..c2b08b36a 100644 --- a/python/port/mod/matplotlib/pyplot/modpyplot.cpp +++ b/python/port/mod/matplotlib/pyplot/modpyplot.cpp @@ -251,23 +251,25 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) { // Initialize bins list mp_obj_t * binItems = m_new(mp_obj_t, nBins); for (size_t i=0; i= lowerBound); + // Increment the bin count + binItems[binIndex] = MP_OBJ_NEW_SMALL_INT(MP_OBJ_SMALL_INT_VALUE(binItems[binIndex]) + 1); xIndex++; - if (xIndex == xLength) { - break; - } } binIndex++; }