Bug Summary

File:jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c
Warning:line 112, column 5
Value stored to 'outputLen' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name EncodingSupport_md.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -D LIBC=gnu -D _GNU_SOURCE -D _REENTRANT -D _LARGEFILE64_SOURCE -D LINUX -D DEBUG -D _LITTLE_ENDIAN -D ARCH="amd64" -D amd64 -D _LP64=1 -I /home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument -I /home/daniel/Projects/java/jdk/src/java.instrument/share/native/libinstrument -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/java.instrument -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjli -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjli -D JPLIS_LOGGING -D _FORTIFY_SOURCE=2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wno-unused -Wno-unused-function -std=c99 -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c /home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c
1/*
2 * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25#include <stdio.h>
26#include <stddef.h>
27#include <stdlib.h>
28#include <string.h>
29#include <ctype.h>
30#include <locale.h>
31#include <langinfo.h>
32#include <iconv.h>
33
34/* Routines to convert back and forth between Platform Encoding and UTF-8 */
35
36/* Error and assert macros */
37#define UTF_ERROR(m)utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 37, m)
utfError(__FILE__"/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c", __LINE__37, m)
38#define UTF_ASSERT(x)( (x)==0 ? utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 38, "ASSERT ERROR " "x") : (void)0 )
( (x)==0 ? UTF_ERROR("ASSERT ERROR " #x)utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 38, "ASSERT ERROR " #x)
: (void)0 )
39#define UTF_DEBUG(x)
40
41/* Global variables */
42static iconv_t iconvToPlatform = (iconv_t)-1;
43static iconv_t iconvFromPlatform = (iconv_t)-1;
44
45/*
46 * Error handler
47 */
48static void
49utfError(char *file, int line, char *message)
50{
51 (void)fprintf(stderr, "UTF ERROR [\"%s\":%d]: %s\n", file, line, message)__fprintf_chk (stderr, 2 - 1, "UTF ERROR [\"%s\":%d]: %s\n", file
, line, message)
;
52 abort();
53}
54
55/*
56 * Initialize all utf processing.
57 */
58static void
59utfInitialize(void)
60{
61 const char* codeset;
62
63#ifndef MACOSX
64 /* Set the locale from the environment */
65 (void)setlocale(LC_ALL6, "");
66
67 /* Get the codeset name */
68 codeset = (char*)nl_langinfo(CODESETCODESET);
69 if ( codeset == NULL((void*)0) || codeset[0] == 0 ) {
70 UTF_DEBUG(("NO codeset returned by nl_langinfo(CODESET)\n"));
71 return;
72 }
73#else /* MACOSX */
74 /* On Mac, platform string (i.e., sun.jnu.encoding value) is always UTF-8 */
75 codeset = "UTF-8";
76#endif
77
78 UTF_DEBUG(("Codeset = %s\n", codeset));
79
80 /* If we don't need this, skip it */
81 if (strcmp(codeset, "UTF-8") == 0 || strcmp(codeset, "utf8") == 0 ) {
82 UTF_DEBUG(("NO iconv() being used because it is not needed\n"));
83 return;
84 }
85
86 /* Open conversion descriptors */
87 iconvToPlatform = iconv_open(codeset, "UTF-8");
88 if ( iconvToPlatform == (iconv_t)-1 ) {
89 UTF_ERROR("Failed to complete iconv_open() setup")utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 89, "Failed to complete iconv_open() setup")
;
90 }
91 iconvFromPlatform = iconv_open("UTF-8", codeset);
92 if ( iconvFromPlatform == (iconv_t)-1 ) {
93 UTF_ERROR("Failed to complete iconv_open() setup")utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 93, "Failed to complete iconv_open() setup")
;
94 }
95}
96
97/*
98 * Do iconv() conversion.
99 * Returns length or -1 if output overflows.
100 */
101static int
102iconvConvert(iconv_t ic, char *bytes, int len, char *output, int outputMaxLen)
103{
104 int outputLen = 0;
105
106 UTF_ASSERT(bytes)( (bytes)==0 ? utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 106, "ASSERT ERROR " "bytes") : (void)0 )
;
107 UTF_ASSERT(len>=0)( (len>=0)==0 ? utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 107, "ASSERT ERROR " "len>=0") : (void)0 )
;
108 UTF_ASSERT(output)( (output)==0 ? utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 108, "ASSERT ERROR " "output") : (void)0 )
;
109 UTF_ASSERT(outputMaxLen>len)( (outputMaxLen>len)==0 ? utfError("/home/daniel/Projects/java/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c"
, 109, "ASSERT ERROR " "outputMaxLen>len") : (void)0 )
;
110
111 output[0] = 0;
112 outputLen = 0;
Value stored to 'outputLen' is never read
113
114 if ( ic != (iconv_t)-1 ) {
115 int returnValue;
116 size_t inLeft;
117 size_t outLeft;
118 char *inbuf;
119 char *outbuf;
120
121 inbuf = bytes;
122 outbuf = output;
123 inLeft = len;
124 outLeft = outputMaxLen;
125 returnValue = iconv(ic, (void*)&inbuf, &inLeft, &outbuf, &outLeft);
126 if ( returnValue >= 0 && inLeft==0 ) {
127 outputLen = outputMaxLen-outLeft;
128 output[outputLen] = 0;
129 return outputLen;
130 }
131
132 /* Failed to do the conversion */
133 UTF_DEBUG(("iconv() failed to do the conversion\n"));
134 return -1;
135 }
136
137 /* Just copy bytes */
138 outputLen = len;
139 (void)memcpy(output, bytes, len);
140 output[len] = 0;
141 return outputLen;
142}
143
144/*
145 * Convert UTF-8 to Platform Encoding.
146 * Returns length or -1 if output overflows.
147 */
148static int
149utf8ToPlatform(char *utf8, int len, char *output, int outputMaxLen)
150{
151 return iconvConvert(iconvToPlatform, utf8, len, output, outputMaxLen);
152}
153
154int
155convertUtf8ToPlatformString(char* utf8_str, int utf8_len, char* platform_str, int platform_len) {
156 if (iconvToPlatform == (iconv_t)-1) {
157 utfInitialize();
158 }
159 return utf8ToPlatform(utf8_str, utf8_len, platform_str, platform_len);
160}