Issue 74117 - Adding runtime checks to static_int_cast
Summary: Adding runtime checks to static_int_cast
Status: CONFIRMED
Alias: None
Product: porting
Classification: Code
Component: code (show other issues)
Version: current
Hardware: All All
: P3 Trivial (vote)
Target Milestone: 4.x
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-02 09:27 UTC by thb
Modified: 2017-05-20 11:31 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Proposed patch (1.02 KB, patch)
2007-02-02 09:27 UTC, thb
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description thb 2007-02-02 09:27:24 UTC
This is a hacked-up enhancement to sal::static_int_cast, which employs
boost::numeric_cast internally (currently, for debug builds only), to perform
range checks for the cast.
Comment 1 thb 2007-02-02 09:27:53 UTC
Created attachment 42662 [details]
Proposed patch
Comment 2 thb 2007-02-02 09:30:21 UTC
I'm aware that including boost headers in sal might be a bad idea, further more,
this incurs a hefty increase in parse time (types.h is prolly included from
_every_ c/cxx file). Comments much appreciated...
Comment 3 thb 2007-02-02 09:34:09 UTC
But generally, I think this or something quite similar will, like STLP_DEBUG,
unearth a couple of quite serious flaws...

But see this for a somewhat different approach to this problem:
http://msdn.microsoft.com/library/en-us/dncode/html/secure01142004_sample.txt
Comment 4 Stephan Bergmann 2007-02-02 09:37:46 UTC
We have deliberately avoided to include boost in the URE API (SDK does not
provide boost in the build environment, but probably does support building with
OSL_DEBUG_LEVEL>0).  That problem might be solved by moving the actual boost
call (and #include "boost/cast.hpp") into a non-inlined function exported from sal.

[The msdn link is a 404 for me, btw.]
Comment 5 thb 2007-02-02 09:46:55 UTC
hrmpf. appears that msdn does not like deep links. try this:
http://msdn2.microsoft.com/en-us/visualc/aa336487.aspx
Comment 6 Stephan Bergmann 2007-02-02 09:48:29 UTC
Also, I am not that happy with extending static_int_cast to arbitrary arithmetic
types.  static_int_cast was introduced in the context of making code warning
free, which often involves converting between different integral types at the
edges of "different worlds" that happen to use different integral types for
similar concepts "by accident."  It was feared that using plain static_cast
instead would make those places harder to find should one of the "different
worlds" decide to change its integral types in the future.

I think conversion between integral and floating point types is rarely (if ever)
necessary at such edges.  (And, it would make "static_int_cast" a misnomer.)
Comment 7 thb 2007-02-02 09:49:52 UTC
regarding boost inclusion: yes, that extra level of indirection might do, but
only if we limit the cast to a finite set of specializations/overloads. And
somewhat related to that problem might be the fact that static_int_cast is a bit
misplaced in types.h ...
Comment 8 thb 2007-02-02 09:52:26 UTC
@sb: regarding integral vs. arithmetic types - yes, I understand the initial
intention. maybe we should enforce this contract?
Comment 9 Stephan Bergmann 2007-02-02 10:17:31 UTC
"that extra level of indirection might do, but only if we limit the cast to a
finite set of specializations/overloads"  Argh, yes, how unfortunate.  However,
"maybe we should enforce this contract?" would fit there nicely again, if we
turn static_int_cast into an explicit set of specializations (and then,
sal/types.h is also a logical place for it, as the set of specializations needs
to be compiler dependent---think of a compiler that has additional, non-standard
integral types).
Comment 10 thb 2007-02-02 11:49:14 UTC
@sb: sounds like a plan to me. will whip up something along this lines...
Comment 11 thb 2007-02-07 09:37:00 UTC
.
Comment 12 thb 2007-06-25 09:51:09 UTC
Retargetted, still needs some work.
Comment 13 Martin Hollmichel 2008-01-25 16:58:35 UTC
set target 3.0
Comment 14 thb 2008-06-04 16:59:53 UTC
Retargetting due to resource constraints
Comment 15 clippka 2011-03-15 16:05:05 UTC
cl->sb: please take over or close
Comment 16 Marcus 2017-05-20 11:31:31 UTC
Reset assigne to the default "issues@openoffice.apache.org".