github-advanced-security[bot] commented on code in PR #754:
URL: https://github.com/apache/datasketches-java/pull/754#discussion_r3867941272


##########
src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java:
##########
@@ -98,4 +123,56 @@
       }
     }
   }
+
+  private static void checkReqNegativeValues(final GroupLanguage lang) {
+    final int[] nArr = {1, 10};
+    for (final int n: nArr) {
+      final String fileName = "req_float_negative_n" + n + lang.sfx + ".sk";
+      final byte[] bytes = getFileBytes(lang.pth, fileName);
+      if (bytes.length == 0) { continue;}
+      //System.out.println(fileName);
+      final ReqSketch sk = ReqSketch.heapify(MemorySegment.ofArray(bytes));
+      assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
+      assertTrue(n > 10 ? sk.isEstimationMode() : !sk.isEstimationMode());
+      assertEquals(sk.getN(), n);
+      if (n > 0) {
+        assertEquals(sk.getMinItem(), -n);
+        assertEquals(sk.getMaxItem(), -1);
+        final QuantilesFloatsSketchIterator it = sk.iterator();
+        long weight = 0;
+        while(it.next()) {
+          assertTrue(it.getQuantile() >= sk.getMinItem());
+          assertTrue(it.getQuantile() <= sk.getMaxItem());
+          weight += it.getWeight();
+        }
+        assertEquals(weight, n);
+      }
+    }
+  }
+
+  private static void checkReqMixedValues(final GroupLanguage lang) {
+    final int[] nArr = {1, 10};
+    for (final int n: nArr) {
+      final String fileName = "req_float_mixed_n" + n + lang.sfx + ".sk";
+      final byte[] bytes = getFileBytes(lang.pth, fileName);
+      if (bytes.length == 0) { continue;}
+      //System.out.println(fileName);
+      final ReqSketch sk = ReqSketch.heapify(MemorySegment.ofArray(bytes));
+      assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
+      if (n == 1)  { assertEquals(sk.getN(), 3); }
+      if (n == 10) { assertEquals(sk.getN(), 21); }
+      if (n > 0) {
+        assertEquals(sk.getMinItem(), -n);
+        assertEquals(sk.getMaxItem(), n);
+        final QuantilesFloatsSketchIterator it = sk.iterator();
+        long weight = 0;
+        while(it.next()) {
+          assertTrue(it.getQuantile() >= sk.getMinItem());
+          assertTrue(it.getQuantile() <= sk.getMaxItem());
+          weight += it.getWeight();
+        }
+        assertEquals(weight, 2 * n + 1);

Review Comment:
   ## CodeQL / Result of multiplication cast to wider type
   
   Potential overflow in [int multiplication](1) before it is converted to long 
by use in an invocation context.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/970)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to