comparison liboctave/util/lo-array-gripes.cc @ 20651:e54ecb33727e

lo-array-gripes.cc: Remove FIXME's related to buffer size. * lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf buffers from 100 to 64 characters (still well more than 19 required). Use 'const' decorator on constant value for clarity. Remove extra space between variable and array bracket.
author Rik <rik@octave.org>
date Mon, 12 Oct 2015 21:13:47 -0700
parents dd6345fd8a97
children
comparison
equal deleted inserted replaced
20650:93d96da9ff3e 20651:e54ecb33727e
120 120
121 std::string 121 std::string
122 index_exception:: access (void) const 122 index_exception:: access (void) const
123 { 123 {
124 // FIXME: don't use a fixed size buffer! 124 // FIXME: don't use a fixed size buffer!
125 125 const int buf_len = 300;
126 int buf_len = 300;
127 126
128 char output [buf_len]; 127 char output [buf_len];
129 char pre [buf_len]; 128 char pre [buf_len];
130 char post [buf_len]; 129 char post [buf_len];
131 130
226 225
227 void 226 void
228 gripe_invalid_index (octave_idx_type n, octave_idx_type nd, 227 gripe_invalid_index (octave_idx_type n, octave_idx_type nd,
229 octave_idx_type dim, const char *var) 228 octave_idx_type dim, const char *var)
230 { 229 {
231 // FIXME: don't use a fixed size buffer! 230 // Note: log10 (2^63) = 19 digits. Use 64 for ease of memory alignment.
232 char buf [100]; 231 char buf[64];
233 232
234 sprintf (buf, "%d", n+1); 233 sprintf (buf, "%d", n+1);
235 234
236 gripe_invalid_index (buf, nd, dim, var); 235 gripe_invalid_index (buf, nd, dim, var);
237 } 236 }
238 237
239 void 238 void
240 gripe_invalid_index (double n, octave_idx_type nd, octave_idx_type dim, 239 gripe_invalid_index (double n, octave_idx_type nd, octave_idx_type dim,
241 const char *var) 240 const char *var)
242 { 241 {
243 // FIXME: don't use a fixed size buffer! 242 char buf[64];
244 char buf [100];
245 243
246 sprintf (buf, "%g", n+1); 244 sprintf (buf, "%g", n+1);
247 245
248 gripe_invalid_index (buf, nd, dim, var); 246 gripe_invalid_index (buf, nd, dim, var);
249 } 247 }
273 271
274 expl = expl + size.str ('x'); 272 expl = expl + size.str ('x');
275 } 273 }
276 else 274 else
277 { 275 {
278 // FIXME: don't use a fixed size buffer! 276 char buf[64];
279 char buf [100];
280 sprintf (buf, "%d", extent); 277 sprintf (buf, "%d", extent);
281 expl = "out of bound " + std::string (buf); 278 expl = "out of bound " + std::string (buf);
282 } 279 }
283 280
284 return expl.c_str (); 281 return expl.c_str ();
294 291
295 void set_extent (octave_idx_type ext) { extent = ext; } 292 void set_extent (octave_idx_type ext) { extent = ext; }
296 293
297 private: 294 private:
298 295
299 dim_vector size; // dimension of object being accessed 296 dim_vector size; // dimension of object being accessed
300 297
301 octave_idx_type extent; // length of dimension being accessed 298 octave_idx_type extent; // length of dimension being accessed
302 }; 299 };
303 300
304 // Complain of an index that is out of range, but we don't know matrix size 301 // Complain of an index that is out of range, but we don't know matrix size
305 void 302 void
306 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, 303 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx,
307 octave_idx_type ext) 304 octave_idx_type ext)
308 { 305 {
309 char buf [100]; 306 char buf[64];
310 sprintf (buf, "%d", idx); 307 sprintf (buf, "%d", idx);
311 out_of_range e (buf, nd, dim); 308 out_of_range e (buf, nd, dim);
312 309
313 e.set_extent (ext); 310 e.set_extent (ext);
314 dim_vector d (1,1,1,1,1,1,1); // make explain() give extent not size 311 dim_vector d (1,1,1,1,1,1,1); // make explain() give extent not size
315 e.set_size (d); 312 e.set_size (d);
316 throw e; 313 throw e;
317 } 314 }
318 315
319 // Complain of an index that is out of range 316 // Complain of an index that is out of range
320 void 317 void
321 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, 318 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx,
322 octave_idx_type ext, const dim_vector& d) 319 octave_idx_type ext, const dim_vector& d)
323 { 320 {
324 char buf [100]; 321 char buf[64];
325 sprintf (buf, "%d", idx); 322 sprintf (buf, "%d", idx);
326 out_of_range e (buf, nd, dim); 323 out_of_range e (buf, nd, dim);
327 324
328 e.set_extent (ext); 325 e.set_extent (ext);
329 e.set_size (d); 326 e.set_size (d);