[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

javahl warnings

From: Philip Martin <philip_at_codematters.co.uk>
Date: Wed, 04 Sep 2013 00:45:36 +0100

../src/subversion/bindings/javahl/native/CreateJ.cpp:861:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
../src/subversion/bindings/javahl/native/JNIUtil.cpp:665:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Both of these are similar:

   664 1456343 brane const jsize stSize = static_cast<jsize>(newStackTra
ce.size());
   665 1456343 brane if (stSize != newStackTrace.size())
   666 1456343 brane {
   667 1456343 brane env->ThrowNew(env->FindClass("java.lang.ArithmeticException"),
   668 1456343 brane "Overflow converting C size_t to JNI jsize");
   669 1456343 brane POP_AND_RETURN_NOTHING();
   670 1456343 brane }

According to the log this is an attempt to detect overflow. Does it
work? jsize is a signed integer type and newStackTrace.size is an an
unsigned type. The types could be different sizes and I think the test
is designed to trigger when the unsigned type is larger than the signed
type and the value is truncated. However the test fails to trigger when
the cast produces a negative value because the types are the same size
and the unsigned value is bigger than the maximum signed value.

I don't think we can use an unsigned type here so I think we need to
compare with something like std::numeric_limits<jsize>::max()
explicitly.

-- 
Philip
Received on 2013-09-04 01:46:34 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.