[xscreensaver] Fix possibly wrong codes detected by cppcheck
Mamoru TASAKA
mtasaka at fedoraproject.org
Tue Feb 10 15:01:02 UTC 2015
commit 7ca64bde9427d93e8967362c56560e8f2df15d10
Author: Mamoru TASAKA <mtasaka at fedoraproject.org>
Date: Wed Feb 11 00:00:50 2015 +0900
Fix possibly wrong codes detected by cppcheck
...substrate-fix-possibly-wrong-memset-usage.patch | 46 ++++++++++++++++++++
...c.c-fix-Unicode-Combining-Diacriticals-Bl.patch | 38 ++++++++++++++++
xscreensaver.spec | 14 ++++++-
3 files changed, 97 insertions(+), 1 deletions(-)
---
diff --git a/xscreensaver-5.32-0006-build_substrate-fix-possibly-wrong-memset-usage.patch b/xscreensaver-5.32-0006-build_substrate-fix-possibly-wrong-memset-usage.patch
new file mode 100644
index 0000000..40c664f
--- /dev/null
+++ b/xscreensaver-5.32-0006-build_substrate-fix-possibly-wrong-memset-usage.patch
@@ -0,0 +1,46 @@
+From e984ceddace7e4e5eaf0b24b690222defb9e46db Mon Sep 17 00:00:00 2001
+From: Mamoru TASAKA <mtasaka at fedoraproject.org>
+Date: Tue, 10 Feb 2015 18:05:41 +0900
+Subject: [PATCH 6/7] build_substrate: fix possibly wrong memset usage
+
+cppcheck warns:
+[hacks/substrate.c:475]: (warning) The 2nd memset() argument '10001' doesn't fit into an 'unsigned char'.
+
+Well, the propotype of memset() says the second argument has type
+'int', however it is actually turned into unsigned char (man 3p memset)
+and puts the number to each *bytes*, so specifying '10001' is highly
+questionable.
+
+Looking at the other part:
+ 195 if (ref_cgrid(f, px, py) < 10000)
+ 196 found = 1;
+
+ 410 if (f->cgrid[cy * f->width + cx] > 10000) {
+
+So perhaps the line 475 actually wanted to put integer number "10001"
+to each integer-array elements.
+---
+ hacks/substrate.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/hacks/substrate.c b/hacks/substrate.c
+index 52d031c..c63ceb9 100644
+--- a/hacks/substrate.c
++++ b/hacks/substrate.c
+@@ -472,7 +472,12 @@ static void build_substrate(struct field *f)
+
+ /* erase the crack grid */
+ f->cgrid = (int *) xrealloc(f->cgrid, sizeof(int) * f->height * f->width);
+- memset(f->cgrid, 10001, f->height * f->width * sizeof(int));
++ {
++ int j;
++ int *p = f->cgrid;
++ for (j = 0; j < f->height * f->width; j++)
++ *p++ = 10001;
++ }
+
+ /* Not necessary now that make_crack ensures we have usable default
+ * values in start_crack's timeout case
+--
+2.1.0
+
diff --git a/xscreensaver-5.32-0007-utils-utf8wc.c-fix-Unicode-Combining-Diacriticals-Bl.patch b/xscreensaver-5.32-0007-utils-utf8wc.c-fix-Unicode-Combining-Diacriticals-Bl.patch
new file mode 100644
index 0000000..5bc3424
--- /dev/null
+++ b/xscreensaver-5.32-0007-utils-utf8wc.c-fix-Unicode-Combining-Diacriticals-Bl.patch
@@ -0,0 +1,38 @@
+From fc06b830187f40f3af28bc0fbf6217c34eb38e25 Mon Sep 17 00:00:00 2001
+From: Mamoru TASAKA <mtasaka at fedoraproject.org>
+Date: Tue, 10 Feb 2015 18:19:40 +0900
+Subject: [PATCH 7/7] utils/utf8wc.c: fix Unicode Combining Diacriticals Block
+ range
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+cppcheck warns:
+[utils/utf8wc.c:347]: (warning) Logical conjunction always evaluates to false: uc >= 8960 && uc <= 879.
+Actually the range check of this line is meaningless.
+
+http://unicode.org/charts/PDF/U0300.pdf says:
+Combining Diacritical Mark
+Range: 0300–036F
+
+So I guess "2" is accidentally typed.
+---
+ utils/utf8wc.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/utils/utf8wc.c b/utils/utf8wc.c
+index ba6806f..d31f049 100644
+--- a/utils/utf8wc.c
++++ b/utils/utf8wc.c
+@@ -344,7 +344,7 @@ utf8_to_latin1 (const char *string, Bool ascii_p)
+
+ if (uc == '\240') /* */
+ uc = ' ';
+- else if (uc >= 0x2300 && uc <= 0x36F)
++ else if (uc >= 0x300 && uc <= 0x36F)
+ uc = 0; /* Discard "Unicode Combining Diacriticals Block" */
+ else if (uc > 0xFF)
+ switch (uc) {
+--
+2.1.0
+
diff --git a/xscreensaver.spec b/xscreensaver.spec
index 02150b8..0b87c6f 100644
--- a/xscreensaver.spec
+++ b/xscreensaver.spec
@@ -10,7 +10,7 @@
%define split_getimage 1
%endif
-%define fedora_rel 7
+%define fedora_rel 8
%global use_clang_as_cc 0
%global use_clang_analyze 0
@@ -89,6 +89,10 @@ Patch203: xscreensaver-5.32-0003-visual.c-pick_best_gl_visual-fix-one-byt
Patch204: xscreensaver-5.32-0004-cubestorm-enable-double-buffer-on-linux.patch
# flush_dialog_changes_and_save: strdup for TEXT entry (bug 1190846)
Patch205: xscreensaver-5.32-0005-flush_dialog_changes_and_save-strdup-for-TEXT-entry.patch
+# cppcheck: build_substrate: fix possibly wrong memset usage
+Patch206: xscreensaver-5.32-0006-build_substrate-fix-possibly-wrong-memset-usage.patch
+# cppcheck: utils/utf8wc.c: fix Unicode Combining Diacriticals Block
+Patch207: xscreensaver-5.32-0007-utils-utf8wc.c-fix-Unicode-Combining-Diacriticals-Bl.patch
#
# Patches end
Requires: xscreensaver-base = %{epoch}:%{version}-%{release}
@@ -353,6 +357,8 @@ gzip -dc %{SOURCE50} > po/ja.po
%__cat %PATCH203 | %__git am
%__cat %PATCH204 | %__git am
%__cat %PATCH205 | %__git am
+%__cat %PATCH206 | %__git am
+%__cat %PATCH207 | %__git am
change_option(){
set +x
@@ -596,6 +602,7 @@ rm -f configure
mkdir clang-analyze
%endif
+%if 0%{?use_clang_analyze} < 1
for dir in \
utils driver hacks hacks/glx po
do
@@ -603,6 +610,8 @@ do
-C $dir \
GMSGFMT="msgfmt --statistics"
done
+%endif
+
# Again
%__make %{?_smp_mflags} -k
@@ -1000,6 +1009,9 @@ exit 0
%endif
%changelog
+* Tue Feb 10 2015 Mamoru TASAKA <mtasaka at fedoraproject.org> - 1:5.32-8
+- Fix possibly wrong codes detected by cppcheck
+
* Tue Feb 10 2015 Mamoru TASAKA <mtasaka at fedoraproject.org> - 1:5.32-7
- flush_dialog_changes_and_save: strdup for TEXT entry (bug 1190846)
More information about the scm-commits
mailing list