|
From: Michal H. <ms...@gm...> - 2012-01-29 20:41:57
|
On Wed, Jan 25, 2012 at 06:28:17PM +0100, Michal Hocko wrote: > Hi, > I have looked at the xpdf changes introduced by pdfeditor project > (http://code.google.com/p/pdfeditor/). > > I would like to clarify some of them before mergin: > [...] > diff --git a/src/xpdf/xpdf/Gfx.cc b/src/xpdf/xpdf/Gfx.cc > index fe1c465..1a29de4 100644 > --- a/src/xpdf/xpdf/Gfx.cc > +++ b/src/xpdf/xpdf/Gfx.cc > @@ -703,10 +703,8 @@ void Gfx::execOp(const Object *cmd, Object args[], int numArgs) { > } > > Operator *Gfx::findOp(const char *name) { > - int a, b, m, cmp; > + int a = -1, b = numOps, m = 0, cmp = 0; > > - a = -1; > - b = numOps; I have double checked this one. The full function looks as follows int a, b, m, cmp; a = -1; b = numOps; // invariant: opTab[a] < name < opTab[b] while (b - a > 1) { m = (a + b) / 2; cmp = strcmp(opTab[m].name, name); if (cmp < 0) a = m; else if (cmp > 0) b = m; else a = b = m; } if (cmp != 0) return NULL; return &opTab[a]; gcc doesn't seem to complain even with -Wall. Anyway, the only issue seems to be that cmp might be used uninitialized if numOps <= 0 but this can never happen because it is defined as sizeof(opTab) / sizeof(Operator). So I would be for reverting this change: --- >From 53f1b1a3d6165dfd63f77937adc7910f3e6f458d Mon Sep 17 00:00:00 2001 From: Michal Hocko <ms...@gm...> Date: Sun, 29 Jan 2012 21:38:09 +0100 Subject: [PATCH] xpdf: revert used by unitialized warning We do not have to initialize m and cmp variables because they can never be used uninitialized because numOps would have to be <= 0 which is not possible as it is defined as sizeof(opTab) / sizeof(Operator). So revert the original fix so that we are closer with the master branch. --- src/xpdf/xpdf/Gfx.cc | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/xpdf/xpdf/Gfx.cc b/src/xpdf/xpdf/Gfx.cc index 1a29de4..a64454b 100644 --- a/src/xpdf/xpdf/Gfx.cc +++ b/src/xpdf/xpdf/Gfx.cc @@ -703,8 +703,10 @@ void Gfx::execOp(const Object *cmd, Object args[], int numArgs) { } Operator *Gfx::findOp(const char *name) { - int a = -1, b = numOps, m = 0, cmp = 0; + int a, b, m, cmp; + a = -1; + b = numOps; // invariant: opTab[a] < name < opTab[b] while (b - a > 1) { m = (a + b) / 2; -- 1.7.8.3 -- Michal Hocko |