[gnumeric] C: Avoid some undefined behaviour problems.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] C: Avoid some undefined behaviour problems.
- Date: Thu, 6 May 2021 00:19:10 +0000 (UTC)
commit a32f4c9bcc55cb07aa4e273fc91a1d73d584fbab
Author: Morten Welinder <terra gnome org>
Date: Wed May 5 00:01:21 2021 -0400
C: Avoid some undefined behaviour problems.
memcpy(dst, NULL, 0) is no good
integer overflow also isn't good
ChangeLog | 8 ++++++++
NEWS | 1 +
src/rangefunc.c | 2 +-
src/workbook.c | 11 ++++++-----
4 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0ecf92bed..08c27ad00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-05-05 Morten Welinder <terra gnome org>
+
+ * src/workbook.c (workbook_cells): Avoid undefined behaviour.
+
+2021-05-04 Morten Welinder <terra gnome org>
+
+ * src/rangefunc.c (gnm_range_adtest): Avoid integer overflow.
+
2021-03-29 Morten Welinder <terra gnome org>
* src/hlink.h (GNM_HLINK_EXTERNAL_TYPE): Add checker macro.
diff --git a/NEWS b/NEWS
index 04c2127ba..faad6163d 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Morten:
* Introspection fixes.
* Improve CELL("format",...) [#576]
* wk4 import improvements. (For no good reason.)
+ * Fix some -fsanitize=undefined problems.
--------------------------------------------------------------------------
Gnumeric 1.12.49
diff --git a/src/rangefunc.c b/src/rangefunc.c
index 97a699fa8..04db922a9 100644
--- a/src/rangefunc.c
+++ b/src/rangefunc.c
@@ -490,7 +490,7 @@ gnm_range_adtest (gnm_float const *xs, int n, gnm_float *pvalue,
total = - n - total/n;
g_free (ys);
- total *= (1 + 0.75 / n + 2.25 / (n * n));
+ total *= (1 + 0.75 / n + 2.25 / ((gnm_float)n * n));
if (total < 0.2)
p = 1. - gnm_exp (-13.436 + 101.14 * total - 223.73 * total * total);
else if (total < 0.34)
diff --git a/src/workbook.c b/src/workbook.c
index 25e7a8c83..f90b50536 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -670,11 +670,12 @@ workbook_cells (Workbook *wb, gboolean comments, GnmSheetVisibility vis)
continue;
scells = sheet_cell_positions (sheet, comments);
- g_ptr_array_set_size (cells, oldlen + scells->len);
- memcpy (&g_ptr_array_index (cells, oldlen),
- &g_ptr_array_index (scells, 0),
- scells->len * sizeof (GnmEvalPos *));
-
+ if (scells->len) {
+ g_ptr_array_set_size (cells, oldlen + scells->len);
+ memcpy (&g_ptr_array_index (cells, oldlen),
+ &g_ptr_array_index (scells, 0),
+ scells->len * sizeof (GnmEvalPos *));
+ }
g_ptr_array_free (scells, TRUE);
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]