[gnumeric] xls: avoid undefined C behaviour.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xls: avoid undefined C behaviour.
- Date: Sun, 8 Dec 2013 03:12:19 +0000 (UTC)
commit 3b50c06aaf5d6d258cf559ac9bbf199716f6738a
Author: Morten Welinder <terra gnome org>
Date: Sat Dec 7 22:11:40 2013 -0500
xls: avoid undefined C behaviour.
plugins/excel/crypt-md4.c | 4 ++--
plugins/excel/ms-excel-write.c | 23 +++++++++++++----------
plugins/excel/ms-formula-write.c | 2 +-
3 files changed, 16 insertions(+), 13 deletions(-)
---
diff --git a/plugins/excel/crypt-md4.c b/plugins/excel/crypt-md4.c
index 55a1f2d..f257f81 100644
--- a/plugins/excel/crypt-md4.c
+++ b/plugins/excel/crypt-md4.c
@@ -21,6 +21,7 @@
*/
/* NOTE: This code makes no attempt to be fast! */
#include <glib.h>
+#include <gsf/gsf.h>
#include <string.h>
#include "crypt-md4.h"
@@ -141,8 +142,7 @@ copy64(guint32 * M, unsigned const char *in)
int i;
for (i = 0; i < 16; i++)
- M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
- (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
+ M[i] = GSF_LE_GET_GUINT32 (in + i * 4);
}
static void
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 1d4595f..d85bf98 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -2082,7 +2082,7 @@ excel_font_hash (gconstpointer f)
ExcelWriteFont *font = (ExcelWriteFont *) f;
if (f)
- res = (int)(font->size_pts + g_str_hash (font->font_name))
+ res = (guint)(font->size_pts + g_str_hash (font->font_name))
^ font->color
^ font->is_auto
^ (font->underline << 1)
@@ -3193,21 +3193,22 @@ excel_write_value (ExcelWriteState *ewb, GnmValue *v, guint32 col, guint32 row,
}
case VALUE_FLOAT: {
gnm_float val = value_get_as_float (v);
- gboolean is_int = (val >= INT_MIN / 4 &&
- val <= INT_MAX / 4 &&
- val == (int)val);
+ gboolean is_int = (val >= G_MININT32 / 4 &&
+ val <= G_MAXINT32 / 4 &&
+ val == gnm_floor (val));
d (3, g_printerr ("Writing %g is (%g %g) is int ? %d\n",
- (double)val,
- (double)(1.0 * (int)val),
- (double)(1.0 * (val - (int)val)),
+ (double)val,
+ (double)(1.0 * gnm_floor (val)),
+ (double)(1.0 * (val - gnm_floor (val))),
is_int););
/* FIXME : Add test for double of form i/100.0
* and represent it as a mode 3 RK (val*100) construct */
if (is_int) {
guint8 *data = ms_biff_put_len_next (ewb->bp, (0x200 | BIFF_RK), 10);
- int ival = (int)val;
+ /* Double cast needed per C99 standard. */
+ guint32 ival = (guint32)(gint32)val;
EX_SETROW(data, row);
EX_SETCOL(data, col);
EX_SETXF (data, xf);
@@ -3789,11 +3790,13 @@ excel_write_DOPER (GnmFilterCondition const *cond, int i, guint8 *buf)
case VALUE_FLOAT: {
gnm_float f = value_get_as_float (v);
- if (f < INT_MIN / 4 || f > INT_MAX / 4 || f != gnm_floor (f)) {
+ if (f < G_MININT32 / 4 ||
+ f > G_MAXINT32 / 4 ||
+ f != gnm_floor (f)) {
buf[0] = 4;
gsf_le_set_double (buf + 2, f);
} else {
- int i = (int)f;
+ guint32 i = (guint32)f;
buf[0] = 2;
GSF_LE_SET_GUINT32 (buf + 2, (i << 2) | 2);
break;
diff --git a/plugins/excel/ms-formula-write.c b/plugins/excel/ms-formula-write.c
index 1dc50df..000cb09 100644
--- a/plugins/excel/ms-formula-write.c
+++ b/plugins/excel/ms-formula-write.c
@@ -41,7 +41,7 @@
static guint
sheet_pair_hash (ExcelSheetPair const *sp)
{
- return ((GPOINTER_TO_INT(sp->a) >> 2) & 0xffff) | ((GPOINTER_TO_INT(sp->b) << 14) & 0xffff0000);
+ return ((GPOINTER_TO_UINT(sp->a) >> 2) & 0xffff) | ((GPOINTER_TO_UINT(sp->b) << 14) & 0xffff0000);
}
static gint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]