[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/internal slice_error.hh vbase.hh
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN/internal slice_error.hh vbase.hh |
Date: |
Tue, 13 Jan 2009 11:58:49 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/01/13 11:58:49
Modified files:
internal : slice_error.hh vbase.hh
Log message:
Slice are now in error if Start <0. This is statically checked where
possible on dynamic vectors.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/slice_error.hh?cvsroot=toon&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.2&r2=1.3
Patches:
Index: slice_error.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/slice_error.hh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- slice_error.hh 9 Jan 2009 16:23:43 -0000 1.2
+++ slice_error.hh 13 Jan 2009 11:58:49 -0000 1.3
@@ -1,19 +1,19 @@
namespace Internal
{
- template<int Size, bool StaticBad>
+ template<bool StaticBad>
struct BadSlice;
- template<int Size>
- struct BadSlice<Size, 0>{
+ template<>
+ struct BadSlice<0>{
static void check(){}
};
- template<int Size=-1, int Start=-1, int Length=-1>
+ template<int Size=-1, int Start=2147483647, int Length=-1>
struct CheckSlice
{
static void check()
{
- BadSlice<Size, (Start+Length>=Size)>::check();
+ BadSlice<(Start < 0) || (Start+Length>=Size)>::check();
}
};
@@ -22,7 +22,9 @@
{
static void check(int size, int start, int length)
{
- if(start + length >= size)
+ BadSlice<(Start != 2147483647 && Start < 0)>::check();
+
+ if(start < 0 || start + length >= size)
{
#ifdef TOON_TEST_INTERNALS
throw Internal::SliceError();
@@ -35,7 +37,7 @@
};
#ifdef TOON_TEST_INTERNALS
- template<int Size, bool StaticBad>
+ template<bool StaticBad>
struct BadSlice{
static void check(){
throw Internal::StaticSliceError();
Index: vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- vbase.hh 13 Jan 2009 10:44:45 -0000 1.2
+++ vbase.hh 13 Jan 2009 11:58:49 -0000 1.3
@@ -281,7 +281,7 @@
template <int Start, int Length>
Vector<Length, Precision, SVBase<Length,1,Precision> >
slice(){
- Internal::CheckSlice<>::check(my_size, Start, Length);
+ Internal::CheckSlice<-1, Start>::check(my_size, Start, Length);
return Vector<Length, Precision, SVBase<Length,1,Precision>
>(&(my_data[Start]));
}
@@ -326,7 +326,7 @@
template <int Start, int Length>
Vector<Length, Precision, SVBase<Length,Stride,Precision> >
slice(){
- Internal::CheckSlice<>::check(my_size, Start, Length);
+ Internal::CheckSlice<-1, Start>::check(my_size, Start, Length);
return Vector<Length, Precision, SVBase<Length,Stride,Precision>
>(&(my_data[Start]));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN/internal slice_error.hh vbase.hh,
Edward Rosten <=