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

Re: javahl warnings

From: Branko Čibej <brane_at_wandisco.com>
Date: Wed, 04 Sep 2013 05:21:11 +0200

On 04.09.2013 01:45, Philip Martin wrote:
> ../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 }

Hmmm ... I don't recall writing that. But no matter.

> 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()

Not necessary. The condition should be

    if (stSize < 0 || stSize != newStackTrace.size())
and then the warning should go away, too; the compiler should know that
both comparands in the second condition are non-negative.

BTW I've no idea why I don't get these warnings when I build JavaHL.

-- Brane

-- 
Branko Čibej | Director of Subversion
WANdisco // Non-Stop Data
e. brane_at_wandisco.com
Received on 2013-09-04 05:22:00 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.