[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: LMDB compiler warning
- To: openldap-technical@openldap.org
- Subject: Re: LMDB compiler warning
- From: Paul Jackson <pj@usa.net>
- Date: Wed, 24 Feb 2016 22:29:56 -0600
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=aDuPwDrt9rvYzhP UMJBwaPwClFU=; b=qPKkn/wn5Km3GoiVNIyoqvuyRhi5YOcRFqNV9XZsJHyQfRn KENlJzvajE1YtqKBy/MgSeMKZ5w261aDsvjJ7M2l90/ibRXv5L5qCIQdIWrlVE/g 82SSXYQHyX2dG9asY0WSix61mDQQsJFmx2y+Vg5y/3FQMKMZFHXM9Kpnknf4=
- In-reply-to: <002501d16eab$a0c3bb20$e24b3160$@comcast.net>
- References: <002501d16eab$a0c3bb20$e24b3160$@comcast.net>
John wrote:
>> only one warning: mdb.c(7224): warning C4333: '>>' : right shift by too large amount, data loss.
It looks to me that the SETDSZ(node,size) macro that is generating that warning on that line
is called three times in mdb.c, twice with a size_t (unsigned int) size, and once, on line 7224
(line varies by version of mdb.c) with an indx_t (unsigned short) size.
The SETDSZ() macro does a right shift by 16 bits to get the higher two bytes of the size,
which is necessary when the size is a size_t (the other two calls), but always produces
zero when the size is an unsigned short (this call giving the warning.)
The poorly worded compiler warning is telling us that it's silly (from the perspective of
the compiler) to be right shifting a 16 bit unsigned short by 16 or more bits to the right.
The result will -always- be zero, suggesting to the compiler that the shift might not be
what the programmer intended.
If this were my software, I would consider changing that invocation of the SETDSZ() macro
from:
SETDSZ(node, nsize);
to:
SETDSZ(node, (size_t)nsize);
to avoid the warning, with no impact on the resulting machine code, but with the benefit
of (minimally) documenting, right in the source code, awareness that this invocation of the
SETDSZ is working with a size that is not of the size_t type expected by the SETDSZ macro.
I have -not- tested the above claims in a Microsoft development environment ... the possibility
for error is non-trivial.
It's better in my view to have no warnings, if that can be done without compromising the
generated code, and only a minor inconvenience to the source code.
Even for experienced C coders (such as myself, who has written many hundreds of thousands
of lines of C code in the last 40 years), the difference in time spent to ensure that all is well,
so far as compiler warnings can detect, is substantially less ... 0 minutes versus N minutes,
when there are zero warnings, rather than one or more warnings.
In my experience, allowing -any- warnings increases the risk that another future warning
that was important will be ignored (probably not by Howard, who knows exactly what is
going on, but perhaps by someone else working with the code.)
--
Paul Jackson
pj@usa.net