[procps] Re: [RFC/PATCH] top: avoid array underflow warnings

  • From: Jim Warner <james.warner@xxxxxxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Thu, 26 May 2016 15:46:54 -0500

On 05/26/2016 02:30 PM, Mike Frysinger wrote:

Commit e1cd74eec9f7dd6918476e963a3a57d99ae61e3d added a call to
make_str where it passed in an empty buffer.  When gcc sees this
with the snprintf logic, it throws a warning about a possible
array underflow:
top/top.c: In function 'task_show':
top/top.c:1528:10: warning: array subscript is below array bounds 
[-Warray-bounds]
        buf[width-1] = COLPLUSCH;

Add an explicit size check to fix that warning.

Hi Mike,

I think that's a spurious warning (that I've yet to experience).

The make_str() width argument can never be zero, even when an empty string passed. And for the commit mentioned, the width will always be 10.

Am I missing something?

Regards,
Jim

p.s. Craig and I have been working on the newlib branch in a bit of a vacuum. We could really use an outside opinion to see if we're on the right track.

Other related posts: