{"action":"created","issue":{"url":"https://api.github.com/repos/uclouvain/openjpeg/issues/719","repository_url":"https://api.github.com/repos/uclouvain/openjpeg","labels_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/719/labels{/name}","comments_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/719/comments","events_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/719/events","html_url":"https://github.com/uclouvain/openjpeg/issues/719","id":137772634,"number":719,"title":"cppcheck static analysis","user":{"login":"setharnold","id":5447148,"avatar_url":"https://avatars.githubusercontent.com/u/5447148?v=3","gravatar_id":"","url":"https://api.github.com/users/setharnold","html_url":"https://github.com/setharnold","followers_url":"https://api.github.com/users/setharnold/followers","following_url":"https://api.github.com/users/setharnold/following{/other_user}","gists_url":"https://api.github.com/users/setharnold/gists{/gist_id}","starred_url":"https://api.github.com/users/setharnold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/setharnold/subscriptions","organizations_url":"https://api.github.com/users/setharnold/orgs","repos_url":"https://api.github.com/users/setharnold/repos","events_url":"https://api.github.com/users/setharnold/events{/privacy}","received_events_url":"https://api.github.com/users/setharnold/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-03-02T04:51:40Z","updated_at":"2016-04-19T19:23:42Z","closed_at":null,"body":"Hello, I inspected OpenJPEG for the Ubuntu Linux distribution; as part of my review I ran the cppcheck static analysis tool on the 1.5.2 and 2.1.0 sources. I only inspected the 1.5.2 results (what is currently packaged in Ubuntu) and found most of the results looked legitimate with only a few false positives.\r\n\r\nI did not inspect the 2.1.0 results beyond noticing that many looked similar to valid issues from 1.5.2.\r\n\r\nI strongly recommend fixing all these issues -- many represent real bugs in the program that may be difficult to discover via other methods. It is worth fixing all the reported issues -- even the ones that represent FILE leaks when main() prematurely terminates -- as it makes it far easier to prevent new issues from entering the codebase when the output is usually clean.\r\n\r\nHere's the list of issues it found:\r\n\r\n[src/bin/jp2/opj_compress.c:1599]: (error) Memory leak: dirptr\r\n[src/bin/jp2/opj_compress.c:1060]: (error) Memory leak: lMatrix\r\n[src/bin/jp2/opj_compress.c:1599]: (error) Memory leak: parameters.cp_comment\r\n[src/bin/jp2/opj_decompress.c:720]: (error) Memory leak: dirptr\r\n[src/bin/jp2/opj_compress.c:631]: (error) Uninitialized variable: raw_signed\r\n[src/bin/jp2/convert.c:130]: (error) Memory leak: tga\r\n[src/bin/jp2/convert.c:1324]: (error) Resource leak: f\r\n[src/bin/jp2/opj_dump.c:453]: (error) Memory leak: dirptr\r\n[src/bin/jp2/convert.c:1880]: (error) Resource leak: fp\r\n[src/bin/jp2/convert.c:3061]: (error) Resource leak: f\r\n[src/bin/jp2/opj_dump.c:439]: (error) Memory leak: l_data\r\n[src/bin/jp2/opj_dump.c:453]: (error) Memory leak: l_data\r\n[src/bin/jp2/opj_dump.c:461]: (error) Memory leak: l_data\r\n[src/bin/jp2/opj_dump.c:466]: (error) Memory leak: l_data\r\n[src/bin/jp2/opj_dump.c:477]: (error) Memory leak: l_data\r\n[src/bin/jp3d/convert.c:300]: (error) Resource leak: f\r\n[src/bin/jp3d/convert.c:690]: (error) Resource leak: fdest\r\n[src/bin/jpwl/convert.c:130]: (error) Memory leak: tga\r\n[src/bin/jpwl/convert.c:1302]: (error) Resource leak: f\r\n[src/bin/jpwl/convert.c:434]: (error) Resource leak: fdest\r\n[src/bin/jpwl/convert.c:714]: (error) Resource leak: IN\r\n[src/bin/jpwl/convert.c:1462]: (error) Resource leak: fdest\r\n[src/bin/jpwl/convert.c:1437]: (error) Memory leak: name\r\n[src/bin/jpwl/convert.c:2889]: (error) Resource leak: f\r\n[src/bin/jpwl/opj_jpwl_compress.c:420]: (error) Memory leak: fname\r\n[src/bin/jpwl/opj_jpwl_compress.c:1562]: (error) Memory leak: dirptr\r\n[src/bin/jpwl/opj_jpwl_decompress.c:564]: (error) Memory leak: dirptr\r\n[src/bin/jpwl/opj_jpwl_compress.c:1728]: (error) Resource leak: f\r\n[src/bin/jpwl/opj_jpwl_compress.c:1789]: (error) Resource leak: f\r\n[src/bin/jpwl/opj_jpwl_compress.c:1562]: (error) Memory leak: parameters.cp_comment\r\n[src/bin/mj2/meta_out.c:684]: (error) fprintf format string requires 1 parameter but only 0 are given.\r\n[src/bin/mj2/meta_out.c:702]: (error) fprintf format string requires 1 parameter but only 0 are given.\r\n[src/bin/mj2/mj2_to_metadata.c:269]: (error) Resource leak: file\r\n[src/bin/mj2/meta_out.c:1836]: (error) Invalid number of character '(' when these macros are defined: 'NOTYET'.\r\n[src/bin/mj2/opj_mj2_compress.c:691]: (error) Resource leak: mj2file\r\n[src/bin/mj2/opj_mj2_decompress.c:101]: (error) Resource leak: outfile\r\n[src/bin/mj2/opj_mj2_decompress.c:161]: (error) Common realloc mistake: 'frame_codestream' nulled but not freed upon failure\r\n[src/bin/mj2/opj_mj2_extract.c:140]: (error) Memory leak: frame_codestream\r\n[src/bin/wx/OPJViewer/source/OPJThreads.cpp:892]: (error) Mismatching allocation and deallocation: buffer\r\n[src/bin/wx/OPJViewer/source/wxj2kparser.cpp:188]: (error) Array 'marker_val[19]' accessed at index 23, which is out of bounds.\r\n[src/bin/wx/OPJViewer/source/wxj2kparser.cpp:188]: (error) Array 'marker_val[20]' accessed at index 23, which is out of bounds.\r\n[src/bin/wx/OPJViewer/source/wxj2kparser.cpp:188]: (error) Array 'marker_val[23]' accessed at index 23, which is out of bounds.\r\n[src/lib/openjp2/j2k.c:8264]: (error) Memory leak: cstr_index\r\n[src/lib/openjp2/j2k.c:3762]: (error) Invalid number of character '{' when these macros are defined: 'CLEAN_MSD'.\r\n[src/lib/openjp3d/jp3d.c:1018]: (error) Uninitialized variable: numbands\r\n[src/lib/openjp3d/tcd.c:1560]: (error) Uninitialized variable: l\r\n[src/lib/openjp3d/tcd.c:1570]: (error) Uninitialized variable: l\r\n[src/lib/openjpip/j2kheader_manager.c:120]: (error) Uninitialized variable: COD\r\n[src/lib/openmj2/j2k.c:1548]: (error) Common realloc mistake: 'data' nulled but not freed upon failure\r\n[src/lib/openmj2/mj2.c:1456]: (error) Array 'tk.urn[urn_num].name[2]' accessed at index 2, which is out of bounds.\r\n[src/lib/openmj2/mj2.c:1457]: (error) Array 'tk.urn[urn_num].name[2]' accessed at index 3, which is out of bounds.\r\n[src/lib/openmj2/mj2.c:1494]: (error) Array 'tk.urn[urn_num].name[2]' accessed at index 2, which is out of bounds.\r\n[src/lib/openmj2/mj2.c:1495]: (error) Array 'tk.urn[urn_num].name[2]' accessed at index 3, which is out of bounds.\r\n[src/lib/openmj2/mj2.c:2709]: (error) Common realloc mistake: 'src' nulled but not freed upon failure\r\n[src/lib/openmj2/mj2.c:2713]: (error) Memory leak: src\r\n[src/lib/openmj2/mj2_convert.c:63]: (error) Resource leak: f\r\n[tests/test_tile_encoder.c:239]: (error) Memory leak: l_data\r\n[thirdparty/libtiff/tif_luv.c:587]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\r\n[thirdparty/libz/gzread.c:345]: (error) Uninitialized variable: n\r\n[thirdparty/libz/gzwrite.c:137]: (error) Uninitialized variable: n\r\n[thirdparty/libz/inflate.c:1475]: (error) Shifting a negative value is undefined behaviour\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/uclouvain/openjpeg/issues/comments/212077198","html_url":"https://github.com/uclouvain/openjpeg/issues/719#issuecomment-212077198","issue_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/719","id":212077198,"user":{"login":"szukw000","id":5041293,"avatar_url":"https://avatars.githubusercontent.com/u/5041293?v=3","gravatar_id":"","url":"https://api.github.com/users/szukw000","html_url":"https://github.com/szukw000","followers_url":"https://api.github.com/users/szukw000/followers","following_url":"https://api.github.com/users/szukw000/following{/other_user}","gists_url":"https://api.github.com/users/szukw000/gists{/gist_id}","starred_url":"https://api.github.com/users/szukw000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szukw000/subscriptions","organizations_url":"https://api.github.com/users/szukw000/orgs","repos_url":"https://api.github.com/users/szukw000/repos","events_url":"https://api.github.com/users/szukw000/events{/privacy}","received_events_url":"https://api.github.com/users/szukw000/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T19:23:42Z","updated_at":"2016-04-19T19:23:42Z","body":"@detonin, @julienmalik .\r\n\r\nHere is the full patch.\r\n\r\nwinfried\r\n[Cppcheck-dif.txt](https://github.com/uclouvain/openjpeg/files/226664/Cppcheck-dif.txt)\r\n"}}