From: Ben Pfaff Date: Sat, 30 Oct 2010 17:30:03 +0000 (-0700) Subject: datasheet: Add a few assertions. X-Git-Tag: v0.7.7~155 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f2df8ad33f0e6d0515f7a1692246f38344597d4;p=pspp-builds.git datasheet: Add a few assertions. These made the problem a bit more obvious while tracking down bug #30689. --- diff --git a/src/data/datasheet.c b/src/data/datasheet.c index 4abc526f..de59e73f 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -360,6 +360,8 @@ datasheet_insert_column (struct datasheet *ds, { struct column *col; + assert (before <= ds->n_columns); + ds->columns = xnrealloc (ds->columns, ds->n_columns + 1, sizeof *ds->columns); insert_element (ds->columns, ds->n_columns, sizeof *ds->columns, before); @@ -382,6 +384,8 @@ datasheet_insert_column (struct datasheet *ds, void datasheet_delete_columns (struct datasheet *ds, size_t start, size_t n) { + assert (start + n <= ds->n_columns); + if (n > 0) { size_t i; @@ -411,6 +415,9 @@ datasheet_move_columns (struct datasheet *ds, size_t old_start, size_t new_start, size_t n) { + assert (old_start + n <= ds->n_columns); + assert (new_start + n <= ds->n_columns); + move_range (ds->columns, ds->n_columns, sizeof *ds->columns, old_start, new_start, n);