aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-07-03 16:41:02 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-07-03 16:41:02 +0200
commit5a8549c6edd0b18fa2315045622bca0f91853796 (patch)
tree4623aec4206d9338e5bcf16a2b71c8898632df80
parentfd9de0086d10ee236dd24d51d93f60edf52cd89c (diff)
parent5651680bbde34de2713d06e868416145e269cb7c (diff)
downloadnx-libs-5a8549c6edd0b18fa2315045622bca0f91853796.tar.gz
nx-libs-5a8549c6edd0b18fa2315045622bca0f91853796.tar.bz2
nx-libs-5a8549c6edd0b18fa2315045622bca0f91853796.zip
Merge branch 'mjtrangoni-WIP-add-cppcheck' into 3.6.x
Attributes GH PR #678: https://github.com/ArcticaProject/nx-libs/pull/678
-rw-r--r--.travis.yml74
-rw-r--r--doc/libNX_X11/lcUniConv/8bit_tab_to_h.c6
-rw-r--r--nx-X11/lib/include/xtrans/Xtrans.c13
-rw-r--r--nx-X11/lib/include/xtrans/Xtranssock.c5
-rw-r--r--nx-X11/programs/Xserver/Xi/exevents.c1
-rw-r--r--nx-X11/programs/Xserver/dix/cursor.c1
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c6
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/NXrender.c1
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/compext/Png.c13
-rw-r--r--nx-X11/programs/Xserver/mi/miexpose.c4
-rw-r--r--nx-X11/programs/Xserver/mi/mizerline.c4
-rw-r--r--nx-X11/programs/Xserver/render/render.c19
-rw-r--r--nxcomp/src/Children.cpp1
-rwxr-xr-xrun-static-analysis.sh14
14 files changed, 118 insertions, 44 deletions
diff --git a/.travis.yml b/.travis.yml
index f8806d063..bc684b578 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,11 +9,24 @@ matrix:
addons:
apt:
sources:
+ - sourceline: 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
- ubuntu-toolchain-r-test
packages:
- - g++-4.9
+ - cppcheck/trusty-backports
+ # imake
+ - xutils-dev
+ # X11 libaries
+ - libxcomposite-dev
+ - libxfont-dev
+ - libxinerama-dev
+ - libxrandr-dev
+ - libxtst-dev
+ - x11proto-fonts-dev
+
env:
- - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
+ - MATRIX_EVAL="CC=gcc && CXX=g++"
+ - STATIC_ANALYSIS="yes"
+ fail_fast: true
- os: linux
addons:
@@ -21,9 +34,20 @@ matrix:
sources:
- ubuntu-toolchain-r-test
packages:
- - g++-7
+ - g++-8
+ # imake
+ - xutils-dev
+ # X11 libaries
+ - libxcomposite-dev
+ - libxfont-dev
+ - libxinerama-dev
+ - libxrandr-dev
+ - libxtst-dev
+ - x11proto-fonts-dev
+
env:
- - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
+ - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
+ - STATIC_ANALYSIS="no"
- os: linux
addons:
@@ -32,25 +56,47 @@ matrix:
- llvm-toolchain-trusty-3.9
packages:
- clang-3.9
+ # imake
+ - xutils-dev
+ # X11 libaries
+ - libxcomposite-dev
+ - libxfont-dev
+ - libxinerama-dev
+ - libxrandr-dev
+ - libxtst-dev
+ - x11proto-fonts-dev
+
env:
- MATRIX_EVAL="CC=clang-3.9 && CXX=clang++-3.9"
+ - STATIC_ANALYSIS="no"
- os: linux
addons:
apt:
sources:
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-trusty-6.0
+ - ubuntu-toolchain-r-test
packages:
- - clang-5.0
+ - clang-6.0
+ - g++-4.9
+ # imake
+ - xutils-dev
+ # X11 libaries
+ - libxcomposite-dev
+ - libxfont-dev
+ - libxinerama-dev
+ - libxrandr-dev
+ - libxtst-dev
+ - x11proto-fonts-dev
+
env:
- - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
+ - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"
+ - STATIC_ANALYSIS="no"
before_install:
- - sudo apt-get update -qq
- # imake
- - sudo apt-get install -y xutils-dev
- # X11 libaries
- - sudo apt-get install -y libxcomposite-dev libxfont-dev libxinerama-dev libxrandr-dev libxtst-dev x11proto-fonts-dev
- - eval "${MATRIX_EVAL}"
+ - eval "${MATRIX_EVAL}"
script:
- - make
+ # run static analysis tools
+ - ./run-static-analysis.sh
+ # build all packages
+ - make
diff --git a/doc/libNX_X11/lcUniConv/8bit_tab_to_h.c b/doc/libNX_X11/lcUniConv/8bit_tab_to_h.c
index 993979aeb..469ec05bb 100644
--- a/doc/libNX_X11/lcUniConv/8bit_tab_to_h.c
+++ b/doc/libNX_X11/lcUniConv/8bit_tab_to_h.c
@@ -121,9 +121,15 @@ int main (int argc, char *argv[])
{
char* fname = malloc(strlen(directory)+strlen(filename)+1);
+ if (fname == NULL)
+ {
+ printf("malloc failed\n");
+ exit(1);
+ }
strcpy(fname,directory); strcat(fname,filename);
f = fopen(fname,"w");
if (f == NULL)
+ free(fname);
exit(1);
}
diff --git a/nx-X11/lib/include/xtrans/Xtrans.c b/nx-X11/lib/include/xtrans/Xtrans.c
index 328a970b1..033dd6cd7 100644
--- a/nx-X11/lib/include/xtrans/Xtrans.c
+++ b/nx-X11/lib/include/xtrans/Xtrans.c
@@ -980,16 +980,17 @@ TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
{
prmsg (1,"GetMyAddr: malloc failed\n");
return -1;
+ } else {
+ memcpy(*addrp, ciptr->addr, ciptr->addrlen);
+ free(addrp);
}
- memcpy(*addrp, ciptr->addr, ciptr->addrlen);
-
return 0;
}
#endif
int
TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
- Xtransaddr **addrp)
+ Xtransaddr **addrp)
{
prmsg (2,"GetPeerAddr(%d)\n", ciptr->fd);
@@ -999,11 +1000,11 @@ TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
if ((*addrp = malloc (ciptr->peeraddrlen)) == NULL)
{
- prmsg (1,"GetPeerAddr: malloc failed\n");
- return -1;
+ prmsg (1,"GetPeerAddr: malloc failed\n");
+ return -1;
}
memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen);
-
+ free(addrp);
return 0;
}
diff --git a/nx-X11/lib/include/xtrans/Xtranssock.c b/nx-X11/lib/include/xtrans/Xtranssock.c
index a7470edcd..090a325ce 100644
--- a/nx-X11/lib/include/xtrans/Xtranssock.c
+++ b/nx-X11/lib/include/xtrans/Xtranssock.c
@@ -2442,19 +2442,18 @@ SocketUNIXConnectPost:
(ciptr->peeraddr = malloc(namelen)) == NULL)
{
prmsg (1,
- "SocketUNIXCreateListener: Can't allocate space for the addr\n");
+ "SocketUNIXCreateListener: Can't allocate space for the addr\n");
return TRANS_CONNECT_FAILED;
}
if (abstract)
- sockname.sun_path[0] = '@';
+ sockname.sun_path[0] = '@';
ciptr->family = AF_UNIX;
ciptr->addrlen = namelen;
ciptr->peeraddrlen = namelen;
memcpy (ciptr->addr, &sockname, ciptr->addrlen);
memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
-
return 0;
}
diff --git a/nx-X11/programs/Xserver/Xi/exevents.c b/nx-X11/programs/Xserver/Xi/exevents.c
index 92b9f08ec..1991d1b29 100644
--- a/nx-X11/programs/Xserver/Xi/exevents.c
+++ b/nx-X11/programs/Xserver/Xi/exevents.c
@@ -656,6 +656,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
if (!others)
return BadAlloc;
if (!pWin->optional->inputMasks && !MakeInputMasks(pWin))
+ free(others);
return BadAlloc;
bzero((char *)&others->mask[0], sizeof(Mask) * EMASKSIZE);
others->mask[mskidx] = mask;
diff --git a/nx-X11/programs/Xserver/dix/cursor.c b/nx-X11/programs/Xserver/dix/cursor.c
index a1bf6a7ed..658edcb87 100644
--- a/nx-X11/programs/Xserver/dix/cursor.c
+++ b/nx-X11/programs/Xserver/dix/cursor.c
@@ -371,6 +371,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
if (!pShare)
{
FreeCursorBits(bits);
+ free(pCurs);
return BadAlloc;
}
pShare->font = sourcefont;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c b/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c
index 04f746aaf..a51ae6fcc 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/NXmiexpose.c
@@ -629,11 +629,13 @@ int what;
screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0,
(XID *)NULL, &status);
if (!screenContext[i])
+ free(prect);
return;
numGCs++;
if (!AddResource(FakeClientID(0), ResType,
- (void *)screenContext[i]))
- return;
+ (void *)screenContext[i]))
+ free(prect);
+ return;
}
pGC = screenContext[i];
newValues[SUBWINDOW].val = IncludeInferiors;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c
index 691b260cf..8937e2e7d 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c
@@ -995,6 +995,7 @@ ProcRenderCompositeGlyphs (ClientPtr client)
{
listsBase = (GlyphListPtr) malloc (nlist * sizeof (GlyphListRec));
if (!listsBase)
+ free(glyphsBase);
return BadAlloc;
}
diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
index 457080032..91412baa1 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c
@@ -283,6 +283,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
bitsPerPixel);
#endif
+ free(image_index);
return NULL;
}
@@ -315,6 +316,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
fprintf(stderr, "******PngCompressData: PANIC! Failed creating the png_create_write_struct.\n");
#endif
+ free(image_index);
return NULL;
}
@@ -327,7 +329,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
#endif
png_destroy_write_struct(&png_ptr, NULL);
-
+ free(image_index);
return NULL;
}
@@ -339,6 +341,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
png_destroy_write_struct(&png_ptr, &info_ptr);
+ free(image_index);
return NULL;
}
@@ -360,6 +363,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
PNG_DEST_SIZE(w, h));
#endif
+ free(image_index);
return NULL;
}
@@ -374,7 +378,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
png_destroy_write_struct(&png_ptr, &info_ptr);
free(pngCompBuf);
-
return NULL;
}
@@ -470,7 +473,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
png_destroy_write_struct(&png_ptr, &info_ptr);
free(pngCompBuf);
-
+ free(image_index);
return NULL;
}
@@ -484,7 +487,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
(int) (w * sizeof(CARD8)));
#endif
-
+ free(image_index);
return NULL;
}
@@ -516,7 +519,7 @@ char *PngCompressData(XImage *image, int *compressed_size)
#endif
free(pngCompBuf);
-
+ free(image_index);
return NULL;
}
diff --git a/nx-X11/programs/Xserver/mi/miexpose.c b/nx-X11/programs/Xserver/mi/miexpose.c
index db7fdf010..a302bf578 100644
--- a/nx-X11/programs/Xserver/mi/miexpose.c
+++ b/nx-X11/programs/Xserver/mi/miexpose.c
@@ -766,11 +766,13 @@ int what;
screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0,
(XID *)NULL, &status);
if (!screenContext[i])
+ free(prect);
return;
numGCs++;
if (!AddResource(FakeClientID(0), ResType,
(void *)screenContext[i]))
- return;
+ free(prect);
+ return;
}
pGC = screenContext[i];
newValues[SUBWINDOW].val = IncludeInferiors;
diff --git a/nx-X11/programs/Xserver/mi/mizerline.c b/nx-X11/programs/Xserver/mi/mizerline.c
index 49d87edd8..c68e2c9a3 100644
--- a/nx-X11/programs/Xserver/mi/mizerline.c
+++ b/nx-X11/programs/Xserver/mi/mizerline.c
@@ -158,7 +158,9 @@ miZeroLine(pDraw, pGC, mode, npt, pptInit)
pspanInit = (DDXPointPtr)malloc(list_len * sizeof(DDXPointRec));
pwidthInit = (int *)malloc(list_len * sizeof(int));
if (!pspanInit || !pwidthInit)
- return;
+ free(pspanInit);
+ free(pwidthInit);
+ return;
Nspans = 0;
new_span = TRUE;
diff --git a/nx-X11/programs/Xserver/render/render.c b/nx-X11/programs/Xserver/render/render.c
index fb9208ad1..65ca41881 100644
--- a/nx-X11/programs/Xserver/render/render.c
+++ b/nx-X11/programs/Xserver/render/render.c
@@ -1346,6 +1346,8 @@ ProcRenderCompositeGlyphs (ClientPtr client)
{
listsBase = (GlyphListPtr) malloc (nlist * sizeof (GlyphListRec));
if (!listsBase)
+ free(glyphsBase);
+ free(listsBase);
return BadAlloc;
}
buffer = (CARD8 *) (stuff + 1);
@@ -2918,9 +2920,7 @@ PanoramiXRenderFillRectangles (ClientPtr client)
result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client);
if(result != Success) break;
}
- free(extra);
}
-
return result;
}
@@ -2979,10 +2979,9 @@ PanoramiXRenderTrapezoids(ClientPtr client)
if(result != Success) break;
}
-
- free(extra);
}
+ free(extra);
return result;
}
@@ -3038,9 +3037,8 @@ PanoramiXRenderTriangles(ClientPtr client)
if(result != Success) break;
}
- free(extra);
}
-
+ free(extra);
return result;
}
@@ -3092,9 +3090,8 @@ PanoramiXRenderTriStrip(ClientPtr client)
if(result != Success) break;
}
- free(extra);
}
-
+ free(extra);
return result;
}
@@ -3146,9 +3143,8 @@ PanoramiXRenderTriFan(ClientPtr client)
if(result != Success) break;
}
- free(extra);
}
-
+ free(extra);
return result;
}
@@ -3276,9 +3272,8 @@ PanoramiXRenderAddTraps (ClientPtr client)
result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client);
if(result != Success) break;
}
- free(extra);
}
-
+ free(extra);
return result;
}
diff --git a/nxcomp/src/Children.cpp b/nxcomp/src/Children.cpp
index 2431e5329..036cffa95 100644
--- a/nxcomp/src/Children.cpp
+++ b/nxcomp/src/Children.cpp
@@ -1038,6 +1038,7 @@ int UnsetEnv(const char *name)
}
result = 0;
+ delete[] varName;
#else
diff --git a/run-static-analysis.sh b/run-static-analysis.sh
new file mode 100755
index 000000000..0524c469a
--- /dev/null
+++ b/run-static-analysis.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+if [[ "${STATIC_ANALYSIS}" == "yes" ]]; then
+ # cppcheck
+ if ! [ -x "$(command -v cppcheck)" ]; then
+ echo 'Error: cppcheck is not installed.' >&2
+ exit 1
+ fi
+ CPPCHECK_OPTS='--error-exitcode=0 --force --quiet'
+ # we exclude some external projects
+ CPPCHECK_EXCLUDES='-i ./nx-X11/extras/Mesa* -i ./nx-X11/extras/Mesa_* -i nx-X11/programs/Xserver/GL/mesa*'
+ echo "$(cppcheck --version):";
+ cppcheck $CPPCHECK_OPTS $CPPCHECK_EXCLUDES .;
+fi