comparison libinterp/corefcn/oct-stream.cc @ 18518:0bdecd41b2dd stable

correctly size fread result (bug #41648) * oct-stream.cc (octave_base_stream::read): When reading to EOF, don't add extra column to the result matrix if the number of elements found is an exact multiple of the number of rows requested. Avoid mixed signed/unsigned comparisons. * io.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Sat, 22 Feb 2014 13:06:18 -0500
parents fdd27f68b011
children f958e8cd6348 aa861a98d84d
comparison
equal deleted inserted replaced
18512:fdd27f68b011 18518:0bdecd41b2dd
3274 3274
3275 size_t gcount = is.gcount (); 3275 size_t gcount = is.gcount ();
3276 3276
3277 char_count += gcount; 3277 char_count += gcount;
3278 3278
3279 size_t nel = gcount / input_elt_size; 3279 octave_idx_type nel = gcount / input_elt_size;
3280 3280
3281 count += nel; 3281 count += nel;
3282 3282
3283 input_buf_list.push_back (input_buf); 3283 input_buf_list.push_back (input_buf);
3284 3284
3295 3295
3296 // Is it possible for this to fail to return us to 3296 // Is it possible for this to fail to return us to
3297 // the original position? 3297 // the original position?
3298 seek (orig_pos, SEEK_SET); 3298 seek (orig_pos, SEEK_SET);
3299 3299
3300 size_t remaining = eof_pos - orig_pos; 3300 off_t remaining = eof_pos - orig_pos;
3301 3301
3302 if (remaining < skip) 3302 if (remaining < skip)
3303 seek (0, SEEK_END); 3303 seek (0, SEEK_END);
3304 else 3304 else
3305 seek (skip, SEEK_CUR); 3305 seek (skip, SEEK_CUR);
3310 } 3310 }
3311 3311
3312 if (read_to_eof) 3312 if (read_to_eof)
3313 { 3313 {
3314 if (nc < 0) 3314 if (nc < 0)
3315 nc = count / nr + 1; 3315 {
3316 nc = count / nr;
3317
3318 if (count % nr != 0)
3319 nc ++;
3320 }
3316 else 3321 else
3317 nr = count; 3322 nr = count;
3318 } 3323 }
3319 else if (count == 0) 3324 else if (count == 0)
3320 { 3325 {