You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2015/01/07 18:07:55 UTC

Unused code in tcnative

All,

There is a function in src/jnilib.c starting on line 119 called
tcn_new_stringn that appears to be unused:

jstring tcn_new_stringn(JNIEnv *env, const char *str, size_t l)

clang brought it to my attention because it's got a logical error in it:

    size_t len = l;

    [...]

    if (l < 0)
        len = strlen(str);

The argument 'l' can never be less than zero because it's declared to be
unsigned. Therefore, the 'len' local will always be the same as the
value of the 'l' argument and is therefore superfluous. Before bothering
to fix the problem, I did a quick grep and I can't find any instances of
a call to that function.

Any objections to simply removing the function entirely?

The function tcn_new_string (without the trailing 'n') is definitely
used. That function does not check to make sure that allocation of the
new string object will succeed (in terms of local references: that is,
it does not call EnsureCapacity). I've only read the miniscule
documentation Oracle provides for NewStringUTF, but is it appropriate to
call EnsureCapacity from tcn_new_string?

Thanks,
-chris