toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN TooN.h internal/allocator.hh


From: Edward Rosten
Subject: [Toon-members] TooN TooN.h internal/allocator.hh
Date: Wed, 25 Mar 2009 22:19:39 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        09/03/25 22:19:39

Modified files:
        .              : TooN.h 
        internal       : allocator.hh 

Log message:
        Explicit throw for negatively sized dynamic matrices.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.18&r2=1.19

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- TooN.h      25 Mar 2009 19:46:08 -0000      1.25
+++ TooN.h      25 Mar 2009 22:19:38 -0000      1.26
@@ -4,6 +4,7 @@
 #include <iostream>
 #include <cstdlib>
 #include <limits>
+#include <new>
 #include <TooN/internal/config.hh>
 #include <TooN/internal/typeof.hh>
 

Index: internal/allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- internal/allocator.hh       25 Mar 2009 21:14:55 -0000      1.18
+++ internal/allocator.hh       25 Mar 2009 22:19:39 -0000      1.19
@@ -194,19 +194,25 @@
 
 template<class Precision> struct MatrixAlloc<-1, -1, Precision>
 {
+       size_t elements(int r, int c)
+       {
+               if(r < 0 || c < 0)
+                       throw std::bad_alloc();
+               return r*c;
+       }
        const int my_rows;
        const int my_cols;
        Precision* const my_data;
 
        MatrixAlloc(const MatrixAlloc& m)
-       :my_rows(m.my_rows),my_cols(m.my_cols),my_data(new Precision[my_rows>=0 
&& my_cols >=0 ?my_rows*my_cols:-1]) {
+       :my_rows(m.my_rows),my_cols(m.my_cols),my_data(new 
Precision[elements(my_rows, my_cols)]){
                const int size=my_rows*my_cols;
                for(int i=0; i < size; i++)
                        my_data[i] = m.my_data[i];
        }
 
        MatrixAlloc(int r, int c)
-       :my_rows(r),my_cols(c),my_data(new Precision[r>=0 && c>=0 ?r*c:-1]) {
+       :my_rows(r),my_cols(c),my_data(new Precision[elements(r, c)]){
        }
 
        ~MatrixAlloc() {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]