From: Mathieu Malaterre Date: Mon, 10 Mar 2014 10:52:09 +0000 (+0000) Subject: [trunk] Properly handle PGM file generation when fullpath is specified in the cmd... X-Git-Tag: version.2.0.1~4^2~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a52b30c3d9aba4de5c21c555b0c159da7f423f4;p=openjpeg [trunk] Properly handle PGM file generation when fullpath is specified in the cmd line This will break a very old behavior (since 2005), but avoid writing in un-expected places for users This also make the behavior similar with PGX file generation --- diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index c170db71..e946ca18 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2106,8 +2106,15 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; for (compno = 0; compno < ncomp; compno++) { - if (ncomp > 1) - sprintf(destname, "%d.%s", compno, outfile); + if (ncomp > 1) + { + /*sprintf(destname, "%d.%s", compno, outfile);*/ + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + + strncpy(destname, outfile, dotpos); + sprintf(destname+dotpos, "_%d.pgm", compno); + } else sprintf(destname, "%s", outfile);