summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-18 10:31:06 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:32 -0500
commit5b862aa38c4fcb1c91797c947ff86b5f70b3ba54 (patch)
tree0f18aedd83d68b5a5f01c5b2128de1f3624b20ce
parent1aa6cdcc1d06dbf5a59ff8f741c0d6185c3517c1 (diff)
downloaduxp-5b862aa38c4fcb1c91797c947ff86b5f70b3ba54.tar.gz
Bug 1352082 - Avoid shifting a signed integer left in C++.
Tag UXP Issue #1344
-rw-r--r--parser/html/java/htmlparser/src/nu/validator/htmlparser/annotation/Unsigned.java30
-rw-r--r--parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java11
-rw-r--r--parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java7
-rw-r--r--parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java4
-rw-r--r--parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java4
-rw-r--r--parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java6
6 files changed, 53 insertions, 9 deletions
diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/annotation/Unsigned.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/annotation/Unsigned.java
new file mode 100644
index 0000000000..53606572a4
--- /dev/null
+++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/annotation/Unsigned.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017 Mozilla Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Applied to an integer type to generate the unsigned variant in C++.
+ */
+package nu.validator.htmlparser.annotation;
+
+public @interface Unsigned {
+
+}
diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java
index 48d82036cb..9cab8c3d09 100644
--- a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java
+++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java
@@ -31,6 +31,7 @@ import nu.validator.htmlparser.annotation.NoLength;
import nu.validator.htmlparser.annotation.NsUri;
import nu.validator.htmlparser.annotation.Prefix;
import nu.validator.htmlparser.annotation.QName;
+import nu.validator.htmlparser.annotation.Unsigned;
import nu.validator.htmlparser.annotation.Virtual;
import nu.validator.htmlparser.common.Interner;
@@ -278,7 +279,7 @@ public final class AttributeName
// ]NOCPP]
, Interner interner) {
// XXX deal with offset
- int hash = AttributeName.bufToHash(buf, length);
+ @Unsigned int hash = AttributeName.bufToHash(buf, length);
int index = Arrays.binarySearch(AttributeName.ATTRIBUTE_HASHES, hash);
if (index < 0) {
return AttributeName.createAttributeName(
@@ -312,9 +313,9 @@ public final class AttributeName
* @param len
* @return
*/
- private static int bufToHash(@NoLength char[] buf, int len) {
- int hash2 = 0;
- int hash = len;
+ private static @Unsigned int bufToHash(@NoLength char[] buf, int len) {
+ @Unsigned int hash2 = 0;
+ @Unsigned int hash = len;
hash <<= 5;
hash += buf[0] - 0x60;
int j = len;
@@ -396,7 +397,7 @@ public final class AttributeName
@Local @NoLength String[] local, @Prefix @NoLength String[] prefix
// [NOCPP[
, int flags
- // ]NOCPP]
+ // ]NOCPP]
) {
this.uri = uri;
this.local = local;
diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java
index ee04933187..39cff44ee2 100644
--- a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java
+++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/ElementName.java
@@ -29,6 +29,7 @@ import java.util.Arrays;
import nu.validator.htmlparser.annotation.Inline;
import nu.validator.htmlparser.annotation.Local;
import nu.validator.htmlparser.annotation.NoLength;
+import nu.validator.htmlparser.annotation.Unsigned;
import nu.validator.htmlparser.annotation.Virtual;
import nu.validator.htmlparser.common.Interner;
@@ -110,7 +111,7 @@ public final class ElementName
}
static ElementName elementNameByBuffer(@NoLength char[] buf, int offset, int length, Interner interner) {
- int hash = ElementName.bufToHash(buf, length);
+ @Unsigned int hash = ElementName.bufToHash(buf, length);
int index = Arrays.binarySearch(ElementName.ELEMENT_HASHES, hash);
if (index < 0) {
return new ElementName(Portability.newLocalNameFromBuffer(buf, offset, length, interner));
@@ -133,8 +134,8 @@ public final class ElementName
* @param len
* @return
*/
- private static int bufToHash(@NoLength char[] buf, int len) {
- int hash = len;
+ private static @Unsigned int bufToHash(@NoLength char[] buf, int len) {
+ @Unsigned int hash = len;
hash <<= 5;
hash += buf[0] - 0x60;
int j = len;
diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
index 337394a89f..dc524820f6 100644
--- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
+++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/AnnotationHelperVisitor.java
@@ -72,6 +72,10 @@ public class AnnotationHelperVisitor<T> extends VoidVisitorAdapter<T> {
return hasAnnotation("NoLength");
}
+ protected boolean unsigned() {
+ return hasAnnotation("Unsigned");
+ }
+
protected boolean auto() {
return hasAnnotation("Auto");
}
diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java
index 80216da0ed..6cbba41628 100644
--- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java
+++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java
@@ -192,6 +192,10 @@ public class CppTypes {
return "int32_t";
}
+ public String unsignedIntType() {
+ return "uint32_t";
+ }
+
public String stringType() {
return "nsHtml5String";
}
diff --git a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
index f4f00070a6..bf5775eb61 100644
--- a/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
+++ b/parser/html/java/htmlparser/translator-src/nu/validator/htmlparser/cpptranslate/CppVisitor.java
@@ -548,7 +548,11 @@ public class CppVisitor extends AnnotationHelperVisitor<LocalSymbolTable> {
case Float:
throw new IllegalStateException("Unsupported primitive.");
case Int:
- printer.print(cppTypes.intType());
+ if (unsigned()) {
+ printer.print(cppTypes.unsignedIntType());
+ } else {
+ printer.print(cppTypes.intType());
+ }
break;
case Long:
throw new IllegalStateException("Unsupported primitive.");