qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs charset.c hex.c html.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs charset.c hex.c html.c
Date: Wed, 15 Mar 2017 19:17:58 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/03/15 19:17:58

Modified files:
        .              : charset.c hex.c html.c 

Log message:
        basic: fix potentially invalid shifts
        - use unsigned arithmetics to avoid implementation-defined behavior
          on (1 << 31)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/qemacs/html.c?cvsroot=qemacs&r1=1.39&r2=1.40

Patches:
Index: charset.c
===================================================================
RCS file: /sources/qemacs/qemacs/charset.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- charset.c   6 Mar 2016 19:53:06 -0000       1.44
+++ charset.c   15 Mar 2017 23:17:58 -0000      1.45
@@ -2,7 +2,7 @@
  * Basic Charset functions for QEmacs
  *
  * Copyright (c) 2000-2002 Fabrice Bellard.
- * Copyright (c) 2002-2016 Charlie Gordon.
+ * Copyright (c) 2002-2017 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -136,9 +136,9 @@
 
 static int probe_8859_1(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + size;
     uint32_t c;
@@ -156,7 +156,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c < 0x7F) {
@@ -363,9 +363,9 @@
 
 static int probe_utf8(qe__unused__ QECharset *charset, const u8 *buf, int size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + size;
     uint32_t c;
@@ -383,7 +383,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c < 0x7F) {
@@ -567,9 +567,9 @@
 
 static int probe_ucs2le(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + (size & ~1);
     uint32_t c;
@@ -590,7 +590,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c >= 0x10000) {
@@ -703,9 +703,9 @@
 
 static int probe_ucs2be(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + (size & ~1);
     uint32_t c;
@@ -726,7 +726,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c >= 0x10000) {
@@ -847,9 +847,9 @@
 
 static int probe_ucs4le(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + (size & ~3);
     uint32_t c;
@@ -870,7 +870,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c > 0x10FFFF) {
@@ -977,9 +977,9 @@
 
 static int probe_ucs4be(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     const u8 *p = buf;
     const u8 *p_end = p + (size & ~3);
     uint32_t c;
@@ -1000,7 +1000,7 @@
             if (c == '\n')
                 count_lines++;
             else
-            if (!(magic & (1 << c)))
+            if (!(magic & (1U << c)))
                 return 0;
         } else
         if (c > 0x10FFFF) {
@@ -1509,13 +1509,13 @@
 
     has_binary = 0;
     {
-        static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                      (1 << '\n') | (1 << '\r') | (1 << 
'\033') |
-                                      (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+        static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << 
'\f') |
+                                      (1U << '\n') | (1U << '\r') | (1U << 
'\033') |
+                                      (1U << 0x0e) | (1U << 0x0f) | (1U << 
0x1f);
 
         for (i = 0; i < size; i++) {
             c = buf[i];
-            if (c < 32 && !(magic & (1 << c)))
+            if (c < 32 && !(magic & (1U << c)))
                 has_binary += 1;
         }
     }

Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- hex.c       27 Dec 2016 10:13:46 -0000      1.49
+++ hex.c       15 Mar 2017 23:17:58 -0000      1.50
@@ -2,7 +2,7 @@
  * Hexadecimal modes for QEmacs.
  *
  * Copyright (c) 2000-2001 Fabrice Bellard.
- * Copyright (c) 2002-2016 Charlie Gordon.
+ * Copyright (c) 2002-2017 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -193,14 +193,14 @@
 
 static int detect_binary(const unsigned char *buf, int size)
 {
-    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
-                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
-                                  (1 << 0x0e) | (1 << 0x0f) | (1 << 0x1f);
+    static const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
+                                  (1U << '\n') | (1U << '\r') | (1U << '\033') 
|
+                                  (1U << 0x0e) | (1U << 0x0f) | (1U << 0x1f);
     int i, c;
 
     for (i = 0; i < size; i++) {
         c = buf[i];
-        if (c < 32 && !(magic & (1 << c)))
+        if (c < 32 && !(magic & (1U << c)))
             return 1;
     }
     return 0;

Index: html.c
===================================================================
RCS file: /sources/qemacs/qemacs/html.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- html.c      9 Jun 2016 16:24:10 -0000       1.39
+++ html.c      15 Mar 2017 23:17:58 -0000      1.40
@@ -2,7 +2,7 @@
  * Graphical HTML mode for QEmacs.
  *
  * Copyright (c) 2001-2002 Fabrice Bellard.
- * Copyright (c) 2003-2016 Charlie Gordon.
+ * Copyright (c) 2003-2017 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -860,7 +860,7 @@
 /* search for HTML tag */
 static int html_mode_probe(ModeDef *mode, ModeProbeData *p1)
 {
-    static const uint32_t magic = (1 << '\r') | (1 << '\n') | (1 << '\t') | (1 
<< '\033');
+    static const uint32_t magic = (1U << '\r') | (1U << '\n') | (1U << '\t') | 
(1U << '\033');
     const unsigned char *p = p1->buf;
     int c, score;
 
@@ -877,7 +877,7 @@
         c = *p;
         if (c == '\0')
             break;
-        if (c < 32 && !(magic & (1 << c)))
+        if (c < 32 && !(magic & (1U << c)))
             return 0;
         if (c == '<' && stristart(cs8(p), "<html", NULL))
             score = 95;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]