You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by vi...@apache.org on 2008/04/11 20:41:53 UTC
svn commit: r647262 - /stdcxx/trunk/tests/localization/22.locale.num.get.cpp
Author: vitek
Date: Fri Apr 11 11:41:51 2008
New Revision: 647262
URL: http://svn.apache.org/viewvc?rev=647262&view=rev
Log:
2008-04-11 Travis Vitek <vi...@roguewave.com>
STDCXX-779
* tests/localization/22.locale.num.get.cpp: Add new macro T_MAX to
eliminate potential for accessing local variable via pointer after
it has gone out of scope. Remove global pointer pmax.
(do_test): Add new pointer parameter pmax.
(test_flt_uflow): Use new T_MAX macro.
(test_dbl_uflow): Ditto.
(test_ldbl_uflow): Ditto.
Modified:
stdcxx/trunk/tests/localization/22.locale.num.get.cpp
Modified: stdcxx/trunk/tests/localization/22.locale.num.get.cpp
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/localization/22.locale.num.get.cpp?rev=647262&r1=647261&r2=647262&view=diff
==============================================================================
--- stdcxx/trunk/tests/localization/22.locale.num.get.cpp (original)
+++ stdcxx/trunk/tests/localization/22.locale.num.get.cpp Fri Apr 11 11:41:51 2008
@@ -235,13 +235,6 @@
/**************************************************************************/
-// if non-zero expected to point to a maximum valid value
-// of type T that's being tested below (used for floating
-// point ranges)
-// on function return, the pointed to value is overwritten
-// with the actual extracted value
-void *pmax = 0;
-
enum IterType { iter_pointer, iter_istreambuf, iter_input };
@@ -251,6 +244,7 @@
const char *cname, // name of character type
IterType itype, // type of input iterator
const char *iname, // name of input iterator
+ void *pmax,
nativeT val, // value expected to be extracted
const char *str, // input sequence
int eat_expect = -1, // number of consumed characters
@@ -444,6 +438,7 @@
const char *cname, // name of character type
IterType itype, // iterator type
const char *iname, // name of iterator type
+ void *pmax,
nativeT val, // value expected to be extracted
const char *str, // input sequence
int eat_expect = -1, // number of consumed characters
@@ -454,15 +449,15 @@
switch (ctype) {
case narrow_char:
return do_test (lineno, (char*)0, cname, itype, iname,
- val, str, eat_expect, flags, err_expect, grouping);
+ pmax, val, str, eat_expect, flags, err_expect, grouping);
case wide_char:
return do_test (lineno, (wchar_t*)0, cname, itype, iname,
- val, str, eat_expect, flags, err_expect, grouping);
+ pmax, val, str, eat_expect, flags, err_expect, grouping);
case user_char:
break;
#if 0 // disabled
return do_test (lineno, (UserChar*)0, cname, itype, iname,
- val, str, eat_expect, flags, err_expect, grouping);
+ pmax, val, str, eat_expect, flags, err_expect, grouping);
#endif // disabled
}
@@ -502,7 +497,8 @@
/*************************************************************************/
#define TEST do_test
-#define T __LINE__, ctype, cname, itype, iname
+#define T __LINE__, ctype, cname, itype, iname, 0
+#define T_MAX __LINE__, ctype, cname, itype, iname, &val
template <class numT>
@@ -2446,7 +2442,6 @@
// exercise bahvior on underflow
float val = 0;
- pmax = &val;
// on underflow, get() follows C99 requirements on strtof()
// i.e., it stores a value in the range [0, +/-FLT_MIN]
@@ -2457,35 +2452,34 @@
// normalized positive number in the return type; whether
// errno acquires the value ERANGE is implementation-defined.
- TEST (T, (val = FLT_MIN, 0.0f), "1.111111e-9999", 14, 0, Eof);
+ TEST (T_MAX, (val = FLT_MIN, 0.0f), "1.111111e-9999", 14, 0, Eof);
rw_assert (!(val < 0.0), 0, __LINE__,
"correct sign after positive underflow");
- TEST (T, (val = 0.0f, -FLT_MIN), "-1.111111e-9999", 15, 0, Eof);
+ TEST (T_MAX, (val = 0.0f, -FLT_MIN), "-1.111111e-9999", 15, 0, Eof);
rw_assert (!(val > 0.0), 0, __LINE__,
"correct sign after negative underflow");
if (1.234567e-39 < FLT_MIN) {
- TEST (T, (val = FLT_MIN, 0.0f), "1.234567e-39", 12, 0, Eof);
- TEST (T, (val = 0.0f, -FLT_MIN), "-1.234567e-39", 13, 0, Eof);
+ TEST (T_MAX, (val = FLT_MIN, 0.0f), "1.234567e-39", 12, 0, Eof);
+ TEST (T_MAX, (val = 0.0f, -FLT_MIN), "-1.234567e-39", 13, 0, Eof);
}
if (1.234567e-49 < FLT_MIN) {
- TEST (T, (val = FLT_MIN, 0.0f), "1.234567e-49", 12, 0, Eof);
- TEST (T, (val = 0.0f, -FLT_MIN), "-1.234567e-49", 13, 0, Eof);
+ TEST (T_MAX, (val = FLT_MIN, 0.0f), "1.234567e-49", 12, 0, Eof);
+ TEST (T_MAX, (val = 0.0f, -FLT_MIN), "-1.234567e-49", 13, 0, Eof);
}
if (1.234567e-99 < FLT_MIN) {
- TEST (T, (val = FLT_MIN, 0.0f), "1.234567e-99", 12, 0, Eof);
- TEST (T, (val = 0.0f, -FLT_MIN), "-1.234567e-99", 13, 0, Eof);
+ TEST (T_MAX, (val = FLT_MIN, 0.0f), "1.234567e-99", 12, 0, Eof);
+ TEST (T_MAX, (val = 0.0f, -FLT_MIN), "-1.234567e-99", 13, 0, Eof);
}
// exercise facet's behavior on underflow:
// parsing succeeds (fail is clear), +/-min is stored
- TEST (T, FLT_MIN, _RWSTD_STRSTR ( _RWSTD_DBL_MIN), -1, 0, Eof);
- TEST (T, -FLT_MIN, _RWSTD_STRSTR (-_RWSTD_DBL_MIN), -1, 0, Eof);
+ TEST (T_MAX, FLT_MIN, _RWSTD_STRSTR ( _RWSTD_DBL_MIN), -1, 0, Eof);
+ TEST (T_MAX, -FLT_MIN, _RWSTD_STRSTR (-_RWSTD_DBL_MIN), -1, 0, Eof);
- pmax = 0; // reset before next test
rw_info (0, 0, 0, "std::num_get<%s, %s>::get (..., float&) on overflow",
@@ -2617,7 +2611,6 @@
// exercise bahvior on underflow
double val = DBL_MIN;
- pmax = &val;
// on underflow, get() follows C99 requirements on strtod()
// i.e., it stores a value in the range [0, +/-DBL_MIN]
@@ -2628,25 +2621,24 @@
// normalized positive number in the return type; whether
// errno acquires the value ERANGE is implementation-defined.
- TEST (T, (val = DBL_MIN, 0.0), "1.111111e-9999", 14, 0, Eof);
- TEST (T, (val = 0.0, -DBL_MIN), "-1.111111e-9999", 15, 0, Eof);
+ TEST (T_MAX, (val = DBL_MIN, 0.0), "1.111111e-9999", 14, 0, Eof);
+ TEST (T_MAX, (val = 0.0, -DBL_MIN), "-1.111111e-9999", 15, 0, Eof);
if (1.23456789e-309L < DBL_MIN) {
- TEST (T, (val = DBL_MIN, 0.0), "1.23456789e-309", 15, 0, Eof);
- TEST (T, (val = 0.0, -DBL_MIN), "-1.23456789e-309", 16, 0, Eof);
+ TEST (T_MAX, (val = DBL_MIN, 0.0), "1.23456789e-309", 15, 0, Eof);
+ TEST (T_MAX, (val = 0.0, -DBL_MIN), "-1.23456789e-309", 16, 0, Eof);
}
if (1.234567e-409L < DBL_MIN) {
- TEST (T, (val = DBL_MIN, 0.0), "1.23456789e-409", 15, 0, Eof);
- TEST (T, (val = 0.0, -DBL_MIN), "-1.23456789e-409", 16, 0, Eof);
+ TEST (T_MAX, (val = DBL_MIN, 0.0), "1.23456789e-409", 15, 0, Eof);
+ TEST (T_MAX, (val = 0.0, -DBL_MIN), "-1.23456789e-409", 16, 0, Eof);
}
if (1.234567e-999L < DBL_MIN) {
- TEST (T, (val = DBL_MIN, 0.0), "1.23456789e-999", 15, 0, Eof);
- TEST (T, (val = 0.0, -DBL_MIN), "-1.23456789e-999", 16, 0, Eof);
+ TEST (T_MAX, (val = DBL_MIN, 0.0), "1.23456789e-999", 15, 0, Eof);
+ TEST (T_MAX, (val = 0.0, -DBL_MIN), "-1.23456789e-999", 16, 0, Eof);
}
- pmax = 0; // reset before next test
# ifdef _RWSTD_LDBL_MAX
@@ -2740,7 +2732,6 @@
// exercise bahvior on underflow
long double val = LDBL_MIN;
- pmax = &val;
// on underflow, get() follows C99 requirements on strtold()
// i.e., it stores a value in the range [0, +/-LDBL__MIN]
@@ -2751,23 +2742,22 @@
// normalized positive number in the return type; whether
// errno acquires the value ERANGE is implementation-defined.
- TEST (T, (val = LDBL_MIN, 0.0L), "1.987654321e-99999", 18, 0, Eof);
- TEST (T, (val = 0.0L, -LDBL_MIN), "-1.987654321e-99999", 19, 0, Eof);
+ TEST (T_MAX, (val = LDBL_MIN, 0.0L), "1.987654321e-99999", 18, 0, Eof);
+ TEST (T_MAX, (val = 0.0L, -LDBL_MIN), "-1.987654321e-99999", 19, 0, Eof);
const char fmt[] = "%Lg";
long double ld = 0.0;
if (1 == std::sscanf ("3.456789e-4932", fmt, &ld) && ld < LDBL_MIN) {
- TEST (T, (val = LDBL_MIN, 0.0L), "3.456789e-4932", 14, 0, Eof);
- TEST (T, (val = 0.0L, -LDBL_MIN), "-3.456789e-4932", 15, 0, Eof);
+ TEST (T_MAX, (val = LDBL_MIN, 0.0L), "3.456789e-4932", 14, 0, Eof);
+ TEST (T_MAX, (val = 0.0L, -LDBL_MIN), "-3.456789e-4932", 15, 0, Eof);
}
if (1 == std::sscanf ("3.456789e-9999", fmt, &ld) && ld < LDBL_MIN) {
- TEST (T, (val = LDBL_MIN, 0.0L), "3.456789e-9999", 14, 0, Eof);
- TEST (T, (val = 0.0L, -LDBL_MIN), "-3.456789e-9999", 15, 0, Eof);
+ TEST (T_MAX, (val = LDBL_MIN, 0.0L), "3.456789e-9999", 14, 0, Eof);
+ TEST (T_MAX, (val = 0.0L, -LDBL_MIN), "-3.456789e-9999", 15, 0, Eof);
}
- pmax = 0; // reset before next test
# ifdef _RWSTD_LDBL_MAX
RE: svn commit: r647262 - /stdcxx/trunk/tests/localization/22.locale.num.get.cpp
Posted by Travis Vitek <Tr...@roguewave.com>.
>Martin Sebor
>
>vitek@apache.org wrote:
>> Author: vitek
>> Date: Fri Apr 11 11:41:51 2008
>> New Revision: 647262
>>
>> URL: http://svn.apache.org/viewvc?rev=647262&view=rev
>> Log:
>>
>> 2008-04-11 Travis Vitek <vi...@roguewave.com>
>>
>> STDCXX-779
>> * tests/localization/22.locale.num.get.cpp: Add new macro
>> T_MAX to eliminate potential for accessing local variable
>> via pointer after it has gone out of scope. Remove global
>> pointer pmax.
>
>Can we make the local variable static instead of all these
>changes? (Global or local, we do want to keep the comment
>about the purpose of pval).
Committed to 4.2.x as r653965.
>
>> (do_test): Add new pointer parameter pmax.
>> (test_flt_uflow): Use new T_MAX macro.
>> (test_dbl_uflow): Ditto.
>> (test_ldbl_uflow): Ditto.
>
>Martin
>
RE: svn commit: r647262 - /stdcxx/trunk/tests/localization/22.locale.num.get.cpp
Posted by Travis Vitek <Tr...@roguewave.com>.
>Martin Sebor wrote:
>
>vitek@apache.org wrote:
>> Author: vitek
>> Date: Fri Apr 11 11:41:51 2008
>> New Revision: 647262
>>
>> URL: http://svn.apache.org/viewvc?rev=647262&view=rev
>> Log:
>>
>> 2008-04-11 Travis Vitek <vi...@roguewave.com>
>>
>> STDCXX-779
>> * tests/localization/22.locale.num.get.cpp: Add new
>macro T_MAX to
>> eliminate potential for accessing local variable via
>pointer after
>> it has gone out of scope. Remove global pointer pmax.
>
>Can we make the local variable static instead of all these
>changes? (Global or local, we do want to keep the comment
>about the purpose of pval).
>
I can't believe I didn't think of that! How silly of me. I'll go back
and make the simpler change.
>> (do_test): Add new pointer parameter pmax.
>> (test_flt_uflow): Use new T_MAX macro.
>> (test_dbl_uflow): Ditto.
>> (test_ldbl_uflow): Ditto.
>
>Martin
>
Re: svn commit: r647262 - /stdcxx/trunk/tests/localization/22.locale.num.get.cpp
Posted by Martin Sebor <se...@roguewave.com>.
vitek@apache.org wrote:
> Author: vitek
> Date: Fri Apr 11 11:41:51 2008
> New Revision: 647262
>
> URL: http://svn.apache.org/viewvc?rev=647262&view=rev
> Log:
>
> 2008-04-11 Travis Vitek <vi...@roguewave.com>
>
> STDCXX-779
> * tests/localization/22.locale.num.get.cpp: Add new macro T_MAX to
> eliminate potential for accessing local variable via pointer after
> it has gone out of scope. Remove global pointer pmax.
Can we make the local variable static instead of all these
changes? (Global or local, we do want to keep the comment
about the purpose of pval).
> (do_test): Add new pointer parameter pmax.
> (test_flt_uflow): Use new T_MAX macro.
> (test_dbl_uflow): Ditto.
> (test_ldbl_uflow): Ditto.
Martin