CoverityFix CID:1350838,1350839,1350840 Dubious method used 88/20388/3
Nimish Kapoor [Mon, 30 Jul 2018 18:54:38 +0000 (23:54 +0530)]
Found a call to a method which will perform a byte to String (or String to
byte) conversion, and will assume that the default platform encoding is
suitable. This will cause the application behaviour to vary between platforms.
Use an alternative API and specify a charset name or Charset object explicitly.

Change-Id: Ibe09e59666a50210c89c578ac3b67d44e69a5e46

scilab/modules/gui/src/java/org/scilab/modules/gui/utils/ScilabPrintStream.java

index 0106216..26ad1b2 100644 (file)
@@ -96,7 +96,7 @@ public final class ScilabPrintStream extends PrintStream {
          * {@inheritDoc}
          */
         public void write(byte[] b) throws IOException {
-            CallScilabBridge.display(new String(b));
+            CallScilabBridge.display(new String(b, "UTF-8"));
             if (out != null) {
                 out.write(b);
             }
@@ -106,7 +106,7 @@ public final class ScilabPrintStream extends PrintStream {
          * {@inheritDoc}
          */
         public void write(byte[] b, int off, int len) throws IOException {
-            CallScilabBridge.display(new String(b, off, len));
+            CallScilabBridge.display(new String(b, off, len, "UTF-8"));
             if (out != null) {
                 out.write(b, off, len);
             }
@@ -116,7 +116,7 @@ public final class ScilabPrintStream extends PrintStream {
          * {@inheritDoc}
          */
         public void write(int b) throws IOException {
-            CallScilabBridge.display(new String (new byte[] {(byte) b}));
+            CallScilabBridge.display(new String (new byte[] {(byte) b}, "UTF-8"));
             if (out != null) {
                 out.write(b);
             }