# HG changeset patch # User Rik # Date 1398445330 25200 # Node ID 5bd1ca29c5f0b563a9d859b935d35611b0a70813 # Parent 1dcc9539234cff9fb9b683135565bb4c0e2fbcf3 Clean up questionable code bits identified by clang sanitize. * data.cc (Fnorm): in %!test, don't test with a single value which exceeds range of single. * find.cc (find_nonzero_elem_idx): Remove unused variable assignment to n_to_find. * load-save.cc (Fsave): Declare argc just before usage. * ls-hdf5.cc (hdf5_read_next_data): Return from function immediately if type is unrecognized. * oct-stream.cc (octave_stream::read): Eliminate unnecessary initialization of elts_to_read. * octave-link.cc (F__octave_link_file_dialog__): Eliminate unnecessary initialization of nel. * pr-output.cc (set_real_format): Don't assign to function input variable digits. * str2double.cc (single_num): Initialize return value num at start of function. * ov-complex.cc (octave_complex::double_value, octave_complex::float_value): Eliminate unnecessary initialization of retval. * ov-flt-complex.cc (octave_float_complex::double_value, octave_float_complex::float_value): Eliminate unnecessary initialization of retval. * CSparse.cc (SparseComplexMatrix::inverse): Remove useless asignment to typ. * CSparse.cc (SparseComplexMatrix::bsolve): Initialize anorm before using in comparison. * MatrixType.cc (matrix_complex_probe): Initialize typ to MatrixType::Unknown. * dSparse.cc (SparseMatrix::inverse): Remove useless assignment to typ. * dSparse.cc (SparseMatrix::bsolve): Initialize anorm before using in comparison. * lo-specfun.cc (gammainc): Remove useless assignment to err. * data-conv.cc (oct_data_conv::string_to_data_type): Remove useless assignment to input_is_output. * str-vec.cc (string_vector::list_in_columns): Remove useless assignment to nc. diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/data.cc Fri Apr 25 10:02:10 2014 -0700 @@ -5353,7 +5353,7 @@ %!assert (norm (x,"inf"), single (7)) %!assert (norm (x,"fro"), single (10), -eps ("single")) %!assert (norm (x), single (10)) -%!assert (norm (single ([1e200, 1])), single (1e200)) +%!assert (norm (single ([1e38, 1])), single (1e38)) %!assert (norm (single ([3+4i, 3-4i, sqrt(31)])), single (9), -4*eps ("single")) %!shared m %! m = single (magic (4)); diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/find.cc --- a/libinterp/corefcn/find.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/find.cc Fri Apr 25 10:02:10 2014 -0700 @@ -239,7 +239,6 @@ if (n_to_find < 0 || n_to_find >= nc) { start_nc = 0; - n_to_find = nc; count = nc; } else if (direction > 0) diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/load-save.cc Fri Apr 25 10:02:10 2014 -0700 @@ -1623,8 +1623,6 @@ { octave_value_list retval; - int argc = args.length (); - string_vector argv = args.make_argv (); if (error_state) @@ -1648,7 +1646,7 @@ // override from command line argv = parse_save_options (argv, format, append, save_as_floats, use_zlib); - argc = argv.length (); + int argc = argv.length (); int i = 0; if (error_state) diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/ls-hdf5.cc Fri Apr 25 10:02:10 2014 -0700 @@ -528,6 +528,7 @@ { warning ("load: can't read '%s' (unknown datatype)", name); retval = 0; // unknown datatype; skip + return retval; } // check for OCTAVE_GLOBAL attribute: diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/oct-stream.cc Fri Apr 25 10:02:10 2014 -0700 @@ -3312,8 +3312,7 @@ if (! error_state) { - octave_idx_type elts_to_read - = std::numeric_limits::max (); + octave_idx_type elts_to_read; if (one_elt_size_spec) { @@ -3342,7 +3341,9 @@ nr = nc = 0; } - // FIXME: ensure that this does not overflow. + // FIXME: Ensure that this does not overflow. + // Maybe try comparing nr * nc computed in double with + // std::numeric_limits::max (); elts_to_read = nr * nc; diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/octave-link.cc --- a/libinterp/corefcn/octave-link.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/octave-link.cc Fri Apr 25 10:02:10 2014 -0700 @@ -225,7 +225,7 @@ std::string multi_on = args(4).string_value (); // on, off, create std::string pathname = args(5).string_value (); - octave_idx_type nel = flist.numel (); + octave_idx_type nel; octave_link::filter_list filter_lst; for (octave_idx_type i = 0; i < flist.rows (); i++) diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/pr-output.cc --- a/libinterp/corefcn/pr-output.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/pr-output.cc Fri Apr 25 10:02:10 2014 -0700 @@ -581,13 +581,11 @@ { ld = digits; rd = prec > digits ? prec - digits : prec; - digits++; } else { ld = 1; rd = prec > digits ? prec - digits : prec; - digits = -digits + 1; } fw = 1 + ld + 1 + rd; diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/corefcn/str2double.cc --- a/libinterp/corefcn/str2double.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/corefcn/str2double.cc Fri Apr 25 10:02:10 2014 -0700 @@ -45,7 +45,7 @@ static double single_num (std::istringstream& is) { - double num; + double num = 0.0; char c = is.peek (); diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/octave-value/ov-complex.cc --- a/libinterp/octave-value/ov-complex.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/octave-value/ov-complex.cc Fri Apr 25 10:02:10 2014 -0700 @@ -105,7 +105,7 @@ double octave_complex::double_value (bool force_conversion) const { - double retval = lo_ieee_nan_value (); + double retval; if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", @@ -119,7 +119,7 @@ float octave_complex::float_value (bool force_conversion) const { - float retval = lo_ieee_float_nan_value (); + float retval; if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", diff -r 1dcc9539234c -r 5bd1ca29c5f0 libinterp/octave-value/ov-flt-complex.cc --- a/libinterp/octave-value/ov-flt-complex.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/libinterp/octave-value/ov-flt-complex.cc Fri Apr 25 10:02:10 2014 -0700 @@ -89,7 +89,7 @@ double octave_float_complex::double_value (bool force_conversion) const { - double retval = lo_ieee_nan_value (); + double retval; if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", @@ -103,7 +103,7 @@ float octave_float_complex::float_value (bool force_conversion) const { - float retval = lo_ieee_float_nan_value (); + float retval; if (! force_conversion) gripe_implicit_conversion ("Octave:imag-to-real", diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/array/CSparse.cc --- a/liboctave/array/CSparse.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/array/CSparse.cc Fri Apr 25 10:02:10 2014 -0700 @@ -1118,7 +1118,6 @@ { // Matrix is either singular or not positive definite mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; } } @@ -4529,7 +4528,7 @@ m_band(ridx (i) - j + n_lower + n_upper, j) = data (i); // Calculate the norm of the matrix, for later use. - double anorm; + double anorm = 0.0; if (calc_cond) { for (octave_idx_type j = 0; j < nr; j++) @@ -4811,7 +4810,7 @@ m_band(ridx (i) - j + n_lower + n_upper, j) = data (i); // Calculate the norm of the matrix, for later use. - double anorm; + double anorm = 0.0; if (calc_cond) { for (octave_idx_type j = 0; j < nr; j++) @@ -5096,7 +5095,7 @@ m_band(ridx (i) - j + n_lower + n_upper, j) = data (i); // Calculate the norm of the matrix, for later use. - double anorm; + double anorm = 0.0; if (calc_cond) { for (octave_idx_type j = 0; j < nr; j++) @@ -5383,7 +5382,7 @@ m_band(ridx (i) - j + n_lower + n_upper, j) = data (i); // Calculate the norm of the matrix, for later use. - double anorm; + double anorm = 0.0; if (calc_cond) { for (octave_idx_type j = 0; j < nr; j++) diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/array/MatrixType.cc --- a/liboctave/array/MatrixType.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/array/MatrixType.cc Fri Apr 25 10:02:10 2014 -0700 @@ -119,7 +119,7 @@ MatrixType::matrix_type matrix_complex_probe (const MArray >& a) { - MatrixType::matrix_type typ; + MatrixType::matrix_type typ = MatrixType::Unknown; octave_idx_type nrows = a.rows (); octave_idx_type ncols = a.cols (); diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/array/dSparse.cc --- a/liboctave/array/dSparse.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/array/dSparse.cc Fri Apr 25 10:02:10 2014 -0700 @@ -1216,7 +1216,6 @@ { // Matrix is either singular or not positive definite mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; } } @@ -4646,7 +4645,7 @@ m_band(ridx (i) - j + n_lower + n_upper, j) = data (i); // Calculate the norm of the matrix, for later use. - double anorm; + double anorm = 0.0; if (calc_cond) { for (octave_idx_type j = 0; j < nr; j++) diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/numeric/lo-specfun.cc --- a/liboctave/numeric/lo-specfun.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/numeric/lo-specfun.cc Fri Apr 25 10:02:10 2014 -0700 @@ -2578,12 +2578,8 @@ err = false; if (a < 0.0 || x < 0.0) - { - (*current_liboctave_error_handler) - ("gammainc: A and X must be non-negative"); - - err = true; - } + (*current_liboctave_error_handler) + ("gammainc: A and X must be non-negative"); else F77_XFCN (xgammainc, XGAMMAINC, (a, x, retval)); @@ -2783,12 +2779,8 @@ err = false; if (a < 0.0 || x < 0.0) - { - (*current_liboctave_error_handler) - ("gammainc: A and X must be non-negative"); - - err = true; - } + (*current_liboctave_error_handler) + ("gammainc: A and X must be non-negative"); else F77_XFCN (xsgammainc, XSGAMMAINC, (a, x, retval)); diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/util/data-conv.cc --- a/liboctave/util/data-conv.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/util/data-conv.cc Fri Apr 25 10:02:10 2014 -0700 @@ -409,8 +409,6 @@ if (input_is_output) { - input_is_output = false; - s1 = s.substr (1, pos-1); (*current_liboctave_warning_handler) diff -r 1dcc9539234c -r 5bd1ca29c5f0 liboctave/util/str-vec.cc --- a/liboctave/util/str-vec.cc Thu Apr 24 14:03:46 2014 -0700 +++ b/liboctave/util/str-vec.cc Fri Apr 25 10:02:10 2014 -0700 @@ -250,14 +250,10 @@ nc = 1; // Calculate the number of rows that will be in each column except - // possibly for a short column on the right. + // possibly for a short column on the right. octave_idx_type nr = total_names / nc + (total_names % nc != 0); - // Recalculate columns based on rows. - - nc = total_names / nr + (total_names % nr != 0); - octave_idx_type count; for (octave_idx_type row = 0; row < nr; row++) {