The following issues were found

java/com/google/scrollview/ScrollView.java
155 issues
System.out.println is used
Design

Line: 62

                /** Add a new message to the outgoing queue */
  public static void addMessage(SVEvent e) {
    if (debugViewNetworkTraffic) {
      System.out.println("(S->c) " + e.toString());
    }
    String str = e.toString();
    // Send the whole thing as UTF8.
    try {
      byte [] utf8 = str.getBytes("UTF8");

            

Reported by PMD.

System.out.println is used
Design

Line: 70

                    byte [] utf8 = str.getBytes("UTF8");
      out.write(utf8, 0, utf8.length);
    } catch (java.io.UnsupportedEncodingException ex) {
      System.out.println("Oops... can't encode to UTF8... Exiting");
      System.exit(0);
    }
    out.println();
    // Flush the output and check for errors.
    boolean error = out.checkError();

            

Reported by PMD.

System.out.println is used
Design

Line: 77

                  // Flush the output and check for errors.
    boolean error = out.checkError();
    if (error) {
      System.out.println("Connection error. Quitting ScrollView Server...");
      System.exit(0);
    }
  }

  /** Read one message from client (assuming there are any). */

            

Reported by PMD.

System.out.println is used
Design

Line: 105

                      }
        nrInputLines++;
        if (debugViewNetworkTraffic) {
          System.out.println("(c->S," + nrInputLines + ")" + inputLine);
        }

        if (polylineSize > polylineScanned) {
          // We are processing a polyline.
          // Read pairs of coordinates separated by commas.

            

Reported by PMD.

System.out.println is used
Design

Line: 130

                  }
    // Some connection error
    catch (IOException e) {
      System.out.println("Connection error. Quitting ScrollView Server...");
    }
    System.exit(0);
  }

  // Parse a comma-separated list of arguments into ArrayLists of the

            

Reported by PMD.

System.out.println is used
Design

Line: 380

              
    // Open a socket to listen on.
    try (ServerSocket serverSocket = new ServerSocket(SERVER_PORT)) {
      System.out.println("Socket started on port " + SERVER_PORT);

      // Wait (blocking) for an incoming connection
      socket = serverSocket.accept();
      System.out.println("Client connected");


            

Reported by PMD.

System.out.println is used
Design

Line: 384

              
      // Wait (blocking) for an incoming connection
      socket = serverSocket.accept();
      System.out.println("Client connected");

      // Setup the streams
      out = new PrintStream(socket.getOutputStream(), true, "UTF-8");
      in =
          new BufferedReader(new InputStreamReader(socket.getInputStream(),

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 32

               * line. It sets up LUA and handles the network processing.
 * @author wanke@google.com
 */
public class ScrollView {

  /** The port our server listens at. */
  public static int SERVER_PORT = 8461;

  /**

            

Reported by PMD.

The class 'ScrollView' has a Modified Cyclomatic Complexity of 10 (Highest = 37).
Design

Line: 32

               * line. It sets up LUA and handles the network processing.
 * @author wanke@google.com
 */
public class ScrollView {

  /** The port our server listens at. */
  public static int SERVER_PORT = 8461;

  /**

            

Reported by PMD.

The class 'ScrollView' has a Standard Cyclomatic Complexity of 10 (Highest = 37).
Design

Line: 32

               * line. It sets up LUA and handles the network processing.
 * @author wanke@google.com
 */
public class ScrollView {

  /** The port our server listens at. */
  public static int SERVER_PORT = 8461;

  /**

            

Reported by PMD.

java/com/google/scrollview/ui/SVWindow.java
85 issues
Avoid reassigning parameters such as 'sizeX'
Design

Line: 202

                 * @param canvasSizeX The canvas width of the window.
   * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;

            

Reported by PMD.

Avoid reassigning parameters such as 'sizeX'
Design

Line: 202

                 * @param canvasSizeX The canvas width of the window.
   * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;

            

Reported by PMD.

Avoid reassigning parameters such as 'sizeY'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'canvasSizeY'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'canvasSizeY'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'canvasSizeX'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'canvasSizeX'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'sizeY'
Design

Line: 203

                 * @param canvasSizeY The canvas height of the window.
   */
  public SVWindow(String name, int hash, int posX, int posY, int sizeX,
                  int sizeY, int canvasSizeX, int canvasSizeY) {
    super(name);

    // Provide defaults for sizes.
    if (sizeX <= 0) sizeX = canvasSizeX;
    if (sizeY <= 0) sizeY = canvasSizeY;

            

Reported by PMD.

Avoid reassigning parameters such as 'y2'
Design

Line: 369

                 * stroke, pen color for the border and the brush to fill the
   * interior.
   */
  public void drawRectangle(int x1, int y1, int x2, int y2) {

    if (x1 > x2) {
      int t = x1;
      x1 = x2;
      x2 = t;

            

Reported by PMD.

Avoid reassigning parameters such as 'x1'
Design

Line: 369

                 * stroke, pen color for the border and the brush to fill the
   * interior.
   */
  public void drawRectangle(int x1, int y1, int x2, int y2) {

    if (x1 > x2) {
      int t = x1;
      x1 = x2;
      x2 = t;

            

Reported by PMD.

src/opencl/openclwrapper.cpp
68 issues
Using 'memset' on struct that contains a 'std::vector' is unsafe, because constructor, destructor and copy operator calls are omitted. These are necessary for this non-POD type to ensure that a valid object is created.
Error

Line: 162 CWE codes: 762

              
  ds_profile *profile = new ds_profile;

  memset(profile, 0, sizeof(ds_profile));

  clGetPlatformIDs(0, nullptr, &numPlatforms);

  if (numPlatforms > 0) {
    platforms.reserve(numPlatforms);

            

Reported by Cppcheck.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 726 Column: 3 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

              inline int OpenclDevice::AddKernelConfig(int kCount, const char *kName) {
  ASSERT_HOST(kCount > 0);
  ASSERT_HOST(strlen(kName) < sizeof(gpuEnv.mArrykernelNames[kCount - 1]));
  strcpy(gpuEnv.mArrykernelNames[kCount - 1], kName);
  gpuEnv.mnKernelCount++;
  return 0;
}

int OpenclDevice::RegistOpenclKernel() {

            

Reported by FlawFinder.

sprintf - Does not check for buffer overflows
Security

Line: 813 Column: 3 CWE codes: 120
Suggestion: Use sprintf_s, snprintf, or vsnprintf

                const char *str = strstr(clFileName, ".cl");
  memcpy(cl_name, clFileName, str - clFileName);
  cl_name[str - clFileName] = '\0';
  sprintf(fileName, "%s-%s.bin", cl_name, deviceName);
  legalizeFileName(fileName);
  fd = fopen(fileName, "rb");
  status = (fd != nullptr) ? 1 : 0;
  if (fd != nullptr) {
    *fhandle = fd;

            

Reported by FlawFinder.

sprintf - Does not check for buffer overflows
Security

Line: 898 Column: 7 CWE codes: 120
Suggestion: Use sprintf_s, snprintf, or vsnprintf

                    const char *str = strstr(clFileName, ".cl");
      memcpy(cl_name, clFileName, str - clFileName);
      cl_name[str - clFileName] = '\0';
      sprintf(fileName, "%s-%s.bin", cl_name, deviceName);
      legalizeFileName(fileName);
      if (!WriteBinaryToFile(fileName, binaries[i], binarySizes[i])) {
        tprintf("[OD] write binary[%s] failed\n", fileName);
        return 0;
      } // else

            

Reported by FlawFinder.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 1027 Column: 3 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                  return 0;
  }

  strcpy(gpuInfo->mArryKnelSrcFile[idx], filename);
  if (binaryExisted == 0) {
    GeneratBinFromKernelSource(gpuInfo->mpArryPrograms[idx], filename);
  }

  gpuInfo->mnFileCount += 1;

            

Reported by FlawFinder.

LoadLibrary - Ensure that the full path to the library is specified, or current directory may be used
Security

Line: 606 Column: 15 CWE codes: 829 20
Suggestion: Use LoadLibraryEx with one of the search flags, or call SetSearchPathMode to use a safe search path, or pass a full path to the library

                void *OpenclDll = nullptr;
  // fprintf(stderr, " LoadOpenclDllxx... \n");
  OpenclDll = static_cast<HINSTANCE>(HOpenclDll);
  OpenclDll = LoadLibrary("openCL.dll");
  if (!static_cast<HINSTANCE>(OpenclDll)) {
    fprintf(stderr, "[OD] Load opencl.dll failed!\n");
    FreeLibrary(static_cast<HINSTANCE>(OpenclDll));
    return 0;
  }

            

Reported by FlawFinder.

srand - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 1790 Column: 3 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

              };

static void populateTessScoreEvaluationInputData(TessScoreEvaluationInputData *input) {
  srand(1);
  // 8.5x11 inches @ 300dpi rounded to clean multiples
  int height = 3328; // %256
  int width = 2560;  // %512
  int numChannels = 4;
  input->height = height;

            

Reported by FlawFinder.

Possible null pointer dereference: env
Error

Line: 1908 CWE codes: 476

                  clock_gettime(CLOCK_MONOTONIC, &time_funct_start);
#  endif

    OpenclDevice::gpuEnv = *env;
    int wpl = pixGetWpl(input.pix);
    OpenclDevice::pixReadFromTiffKernel(tiffdata, input.width, input.height, wpl, nullptr);
#  if ON_WINDOWS
    QueryPerformanceCounter(&time_funct_end);
    time = (time_funct_end.QuadPart - time_funct_start.QuadPart) / (double)(freq.QuadPart);

            

Reported by Cppcheck.

Possible null pointer dereference: env
Error

Line: 1992 CWE codes: 476

                  clock_gettime(CLOCK_MONOTONIC, &time_funct_start);
#  endif

    OpenclDevice::gpuEnv = *env;
    int retVal = OpenclDevice::HistogramRectOCL(input.imageData, input.numChannels, bytes_per_line,
                                                left, top, input.width, input.height,
                                                kHistogramSize, histogramAllChannels);

#  if ON_WINDOWS

            

Reported by Cppcheck.

Possible null pointer dereference: env
Error

Line: 2110 CWE codes: 476

                  clock_gettime(CLOCK_MONOTONIC, &time_funct_start);
#  endif

    OpenclDevice::gpuEnv = *env;
    int hi_values[4];
    int retVal = OpenclDevice::ThresholdRectToPixOCL(
        input.imageData, input.numChannels, bytes_per_line, thresholds, hi_values, &input.pix,
        input.height, input.width, top, left);


            

Reported by Cppcheck.

java/com/google/scrollview/events/SVEventHandler.java
62 issues
No need to import a type that lives in the same package
Error

Line: 14

              package com.google.scrollview.events;

import com.google.scrollview.ScrollView;
import com.google.scrollview.events.SVEvent;
import com.google.scrollview.events.SVEventType;
import com.google.scrollview.ui.SVWindow;

import org.piccolo2d.PCamera;
import org.piccolo2d.PNode;

            

Reported by PMD.

No need to import a type that lives in the same package
Error

Line: 15

              
import com.google.scrollview.ScrollView;
import com.google.scrollview.events.SVEvent;
import com.google.scrollview.events.SVEventType;
import com.google.scrollview.ui.SVWindow;

import org.piccolo2d.PCamera;
import org.piccolo2d.PNode;
import org.piccolo2d.event.PBasicInputEventHandler;

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 44

               * @author wanke@google.com
 */
public class SVEventHandler extends PBasicInputEventHandler implements
    ActionListener, KeyListener, WindowListener {

  /** Necessary to wait for a defined period of time (for SVET_HOVER). */
  public Timer timer;

  /** The window which the event corresponds to. */

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 47

                  ActionListener, KeyListener, WindowListener {

  /** Necessary to wait for a defined period of time (for SVET_HOVER). */
  public Timer timer;

  /** The window which the event corresponds to. */
  private SVWindow svWindow;

  /** These are used to determine a selection size (for SVET_SELECTION). */

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 50

                public Timer timer;

  /** The window which the event corresponds to. */
  private SVWindow svWindow;

  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;


            

Reported by PMD.

Private field 'svWindow' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 50

                public Timer timer;

  /** The window which the event corresponds to. */
  private SVWindow svWindow;

  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;


            

Reported by PMD.

Avoid using redundant field initializer for 'lastX'
Performance

Line: 53

                private SVWindow svWindow;

  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;

  /**
   * These are used in case we want to transmit our position, but do not get it
   * because it was no MouseEvent, in particular SVET_HOVER and SVET_INPUT.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 53

                private SVWindow svWindow;

  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;

  /**
   * These are used in case we want to transmit our position, but do not get it
   * because it was no MouseEvent, in particular SVET_HOVER and SVET_INPUT.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 54

              
  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;

  /**
   * These are used in case we want to transmit our position, but do not get it
   * because it was no MouseEvent, in particular SVET_HOVER and SVET_INPUT.
   */

            

Reported by PMD.

Avoid using redundant field initializer for 'lastY'
Performance

Line: 54

              
  /** These are used to determine a selection size (for SVET_SELECTION). */
  private int lastX = 0;
  private int lastY = 0;

  /**
   * These are used in case we want to transmit our position, but do not get it
   * because it was no MouseEvent, in particular SVET_HOVER and SVET_INPUT.
   */

            

Reported by PMD.

unittest/stringrenderer_test.cc
48 issues
syntax error
Error

Line: 82

                std::unique_ptr<StringRenderer> renderer_;
};

TEST_F(StringRendererTest, DoesRenderToImage) {
  renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
  Image pix = nullptr;
  EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);

            

Reported by Cppcheck.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 85 Column: 13 CWE codes: 126

              TEST_F(StringRendererTest, DoesRenderToImage) {
  renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
  Image pix = nullptr;
  EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();


            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 85 Column: 66 CWE codes: 126

              TEST_F(StringRendererTest, DoesRenderToImage) {
  renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
  Image pix = nullptr;
  EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();


            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 92 Column: 13 CWE codes: 126

                pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("UnBatang 10", 600, 600);
  EXPECT_EQ(strlen(kKorText), renderer_->RenderToImage(kKorText, strlen(kKorText), &pix));
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("Lohit Hindi 10", 600, 600);

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 92 Column: 66 CWE codes: 126

                pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("UnBatang 10", 600, 600);
  EXPECT_EQ(strlen(kKorText), renderer_->RenderToImage(kKorText, strlen(kKorText), &pix));
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("Lohit Hindi 10", 600, 600);

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 98 Column: 13 CWE codes: 126

                pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("Lohit Hindi 10", 600, 600);
  EXPECT_EQ(strlen(kHinText), renderer_->RenderToImage(kHinText, strlen(kHinText), &pix));
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();

  // RTL text

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 98 Column: 66 CWE codes: 126

                pix.destroy();

  renderer_ = std::make_unique<StringRenderer>("Lohit Hindi 10", 600, 600);
  EXPECT_EQ(strlen(kHinText), renderer_->RenderToImage(kHinText, strlen(kHinText), &pix));
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();

  // RTL text

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 105 Column: 13 CWE codes: 126

              
  // RTL text
  renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
  EXPECT_EQ(strlen(kArabicText), renderer_->RenderToImage(kArabicText, strlen(kArabicText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();


            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 105 Column: 72 CWE codes: 126

              
  // RTL text
  renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
  EXPECT_EQ(strlen(kArabicText), renderer_->RenderToImage(kArabicText, strlen(kArabicText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();


            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 113 Column: 70 CWE codes: 126

              
  // Mixed direction Arabic + english text
  renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
  EXPECT_EQ(strlen(kMixedText), renderer_->RenderToImage(kMixedText, strlen(kMixedText), &pix));
  EXPECT_TRUE(pix != nullptr);
  EXPECT_GT(renderer_->GetBoxes().size(), 0);
  DisplayClusterBoxes(pix);
  pix.destroy();
}

            

Reported by FlawFinder.

src/ccstruct/points.h
23 issues
syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

syntax error
Error

Line: 195

                /// constructor
  ///@param xvalue x value
  ///@param yvalue y value
  FCOORD(float xvalue, float yvalue) {
    xcoord = xvalue; // set coords
    ycoord = yvalue;
  }
  FCOORD(              // make from ICOORD
      ICOORD icoord) { // coords to set

            

Reported by Cppcheck.

src/ccutil/scanutils.cpp
23 issues
fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 67 Column: 22 CWE codes: 120 20

              
static inline int SkipSpace(FILE *s) {
  int p;
  while (isascii(p = fgetc(s)) && isspace(p)) {
    ;
  }
  ungetc(p, s); // Make sure next char is available for reading
  return p;
}

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 101 Column: 12 CWE codes: 120 20

                uintmax_t v = 0;
  int d, c = 0;

  for (c = fgetc(s); isascii(c) && isspace(c); c = fgetc(s)) {
    ;
  }

  // Single optional + or -
  if (c == '-' || c == '+') {

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 101 Column: 52 CWE codes: 120 20

                uintmax_t v = 0;
  int d, c = 0;

  for (c = fgetc(s); isascii(c) && isspace(c); c = fgetc(s)) {
    ;
  }

  // Single optional + or -
  if (c == '-' || c == '+') {

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 108 Column: 9 CWE codes: 120 20

                // Single optional + or -
  if (c == '-' || c == '+') {
    minus = (c == '-');
    c = fgetc(s);
  }

  // Assign correct base
  if (base == 0) {
    if (c == '0') {

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 114 Column: 11 CWE codes: 120 20

                // Assign correct base
  if (base == 0) {
    if (c == '0') {
      c = fgetc(s);
      if (c == 'x' || c == 'X') {
        base = 16;
        c = fgetc(s);
      } else {
        base = 8;

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 117 Column: 13 CWE codes: 120 20

                    c = fgetc(s);
      if (c == 'x' || c == 'X') {
        base = 16;
        c = fgetc(s);
      } else {
        base = 8;
      }
    }
  } else if (base == 16) {

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 124 Column: 11 CWE codes: 120 20

                  }
  } else if (base == 16) {
    if (c == '0') {
      c = fgetc(s);
      if (c == 'x' || c == 'X') {
        c = fgetc(s);
      }
    }
  }

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 126 Column: 13 CWE codes: 120 20

                  if (c == '0') {
      c = fgetc(s);
      if (c == 'x' || c == 'X') {
        c = fgetc(s);
      }
    }
  }

  // Actual number parsing

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 132 Column: 60 CWE codes: 120 20

                }

  // Actual number parsing
  for (; (c != EOF) && (d = DigitValue(c, base)) >= 0; c = fgetc(s)) {
    v = v * base + d;
  }

  ungetc(c, s);
  return minus ? -v : v;

            

Reported by FlawFinder.

fgetc - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 147 Column: 12 CWE codes: 120 20

                uint64_t k = 1;
  uint64_t w = 0;

  for (c = fgetc(s); isascii(c) && isspace(c); c = fgetc(s)) {
    ;
  }

  // Single optional + or -
  if (c == '-' || c == '+') {

            

Reported by FlawFinder.

java/com/google/scrollview/ui/SVMenuBar.java
20 issues
System.out.println is used
Design

Line: 95

                  else {
      SVAbstractMenuItem jmi = items.get(parent);
      if (jmi == null) {
        System.out.println("ERROR: Unknown parent " + parent);
        System.exit(1);
      }
      SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name);
      mli.mi.addActionListener(this);
      items.put(name, mli);

            

Reported by PMD.

System.out.println is used
Design

Line: 121

                public void add(String parent, String name, int id, boolean b) {
    SVAbstractMenuItem jmi = items.get(parent);
    if (jmi == null) {
      System.out.println("ERROR: Unknown parent " + parent);
      System.exit(1);
    }
    SVAbstractMenuItem mli = new SVCheckboxMenuItem(id, name, b);
    mli.mi.addActionListener(this);
    items.put(name, mli);

            

Reported by PMD.

No need to import a type that lives in the same package
Error

Line: 14

              package com.google.scrollview.ui;

import com.google.scrollview.events.SVEventType;
import com.google.scrollview.ui.SVWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;


            

Reported by PMD.

Private field 'root' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 33

               */
public class SVMenuBar implements ActionListener {
  /** The root entry to add items to. */
  private JMenuBar root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

               */
public class SVMenuBar implements ActionListener {
  /** The root entry to add items to. */
  private JMenuBar root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;


            

Reported by PMD.

Private field 'items' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 35

                /** The root entry to add items to. */
  private JMenuBar root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVMenuBar and place it at the top of the ScrollView window.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

                /** The root entry to add items to. */
  private JMenuBar root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVMenuBar and place it at the top of the ScrollView window.

            

Reported by PMD.

Avoid using implementation types like 'HashMap'; use the interface instead
Design

Line: 35

                /** The root entry to add items to. */
  private JMenuBar root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVMenuBar and place it at the top of the ScrollView window.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 37

                /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVMenuBar and place it at the top of the ScrollView window.
   *
   * @param scrollView The window our menubar belongs to.

            

Reported by PMD.

Private field 'svWindow' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 37

                /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVMenuBar and place it at the top of the ScrollView window.
   *
   * @param scrollView The window our menubar belongs to.

            

Reported by PMD.

src/ccutil/unicharset.cpp
19 issues
strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 1045 Column: 3 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                  script_table = new_script_table;
  }
  script_table[script_table_size_used] = new char[strlen(script) + 1];
  strcpy(script_table[script_table_size_used], script);
  return script_table_size_used++;
}

// Returns the string that represents a fragment
// with the given unichar, pos and total.

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 305 Column: 5 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                int step = 1;
  // Chop into unicodes and code each as hex.
  for (int i = 0; str[i] != '\0'; i += step) {
    char hex[sizeof(int) * 2 + 1];
    step = UNICHAR::utf8_step(str + i);
    if (step == 0) {
      step = 1;
      sprintf(hex, "%x", str[i]);
    } else {

            

Reported by FlawFinder.

sprintf - Does not check for buffer overflows
Security

Line: 309 Column: 7 CWE codes: 120
Suggestion: Use sprintf_s, snprintf, or vsnprintf

                  step = UNICHAR::utf8_step(str + i);
    if (step == 0) {
      step = 1;
      sprintf(hex, "%x", str[i]);
    } else {
      UNICHAR ch(str + i, step);
      sprintf(hex, "%x", ch.first_uni());
    }
    result += hex;

            

Reported by FlawFinder.

sprintf - Does not check for buffer overflows
Security

Line: 312 Column: 7 CWE codes: 120
Suggestion: Use sprintf_s, snprintf, or vsnprintf

                    sprintf(hex, "%x", str[i]);
    } else {
      UNICHAR ch(str + i, step);
      sprintf(hex, "%x", ch.first_uni());
    }
    result += hex;
    result += " ";
  }
  result += "]";

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 697 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              
bool UNICHARSET::save_to_string(std::string &str) const {
  const int kFileBufSize = 1024;
  char buffer[kFileBufSize + 1];
  snprintf(buffer, kFileBufSize, "%d\n", this->size());
  str = buffer;
  for (UNICHAR_ID id = 0; id < this->size(); ++id) {
    int min_bottom, max_bottom, min_top, max_top;
    get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 758 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              
bool UNICHARSET::load_via_fgets(std::function<char *(char *, int)> fgets_cb, bool skip_fragments) {
  int unicharset_size;
  char buffer[256];

  this->clear();
  if (fgets_cb(buffer, sizeof(buffer)) == nullptr || sscanf(buffer, "%d", &unicharset_size) != 1) {
    return false;
  }

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 765 Column: 5 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                  return false;
  }
  for (UNICHAR_ID id = 0; id < unicharset_size; ++id) {
    char unichar[256];
    unsigned int properties;
    char script[64];

    strncpy(script, null_script, sizeof(script) - 1);
    int min_bottom = 0;

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 767 Column: 5 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                for (UNICHAR_ID id = 0; id < unicharset_size; ++id) {
    char unichar[256];
    unsigned int properties;
    char script[64];

    strncpy(script, null_script, sizeof(script) - 1);
    int min_bottom = 0;
    int max_bottom = UINT8_MAX;
    int min_top = 0;

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 788 Column: 5 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                  if (fgets_cb(buffer, sizeof(buffer)) == nullptr) {
      return false;
    }
    char normed[64];
    normed[0] = '\0';
    std::istringstream stream(buffer);
    stream.imbue(std::locale::classic());
    // 标 1 0,255,0,255,0,0,0,0,0,0 Han 68 0 68 标  # 标 [6807 ]x
    // stream.flags(std::ios::hex);

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1035 Column: 24 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                }
  if (script_table_size_reserved == 0) {
    script_table_size_reserved = 8;
    script_table = new char *[script_table_size_reserved];
  } else if (script_table_size_used >= script_table_size_reserved) {
    assert(script_table_size_used == script_table_size_reserved);
    script_table_size_reserved += script_table_size_reserved;
    char **new_script_table = new char *[script_table_size_reserved];
    memcpy(new_script_table, script_table, script_table_size_used * sizeof(char *));

            

Reported by FlawFinder.

java/com/google/scrollview/ui/SVPopupMenu.java
19 issues
System.out.println is used
Design

Line: 86

                  else {
      SVAbstractMenuItem jmi = items.get(parent);
      if (jmi == null) {
        System.out.println("ERROR: Unknown parent " + parent);
        System.exit(1);
      }
      SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name);
      mli.mi.addActionListener(this);
      items.put(name, mli);

            

Reported by PMD.

No need to import a type that lives in the same package
Error

Line: 14

              package com.google.scrollview.ui;

import com.google.scrollview.events.SVEventType;
import com.google.scrollview.ui.SVMenuItem;
import com.google.scrollview.ui.SVWindow;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

            

Reported by PMD.

No need to import a type that lives in the same package
Error

Line: 15

              
import com.google.scrollview.events.SVEventType;
import com.google.scrollview.ui.SVMenuItem;
import com.google.scrollview.ui.SVWindow;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

            

Reported by PMD.

Private field 'root' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 36

              
public class SVPopupMenu implements ActionListener {
  /** The root entry to add items to. */
  private JPopupMenu root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

              
public class SVPopupMenu implements ActionListener {
  /** The root entry to add items to. */
  private JPopupMenu root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 38

                /** The root entry to add items to. */
  private JPopupMenu root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVPopupMenu and associate it with a ScrollView window.

            

Reported by PMD.

Avoid using implementation types like 'HashMap'; use the interface instead
Design

Line: 38

                /** The root entry to add items to. */
  private JPopupMenu root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVPopupMenu and associate it with a ScrollView window.

            

Reported by PMD.

Private field 'items' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 38

                /** The root entry to add items to. */
  private JPopupMenu root;
  /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVPopupMenu and associate it with a ScrollView window.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 40

                /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVPopupMenu and associate it with a ScrollView window.
   *
   * @param sv The window our popup menu belongs to.

            

Reported by PMD.

Private field 'svWindow' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 40

                /** Contains a map of item name to its actual entry. */
  private HashMap<String, SVAbstractMenuItem> items;
  /** The window the menubar belongs to. */
  private SVWindow svWindow;

  /**
   * Create a new SVPopupMenu and associate it with a ScrollView window.
   *
   * @param sv The window our popup menu belongs to.

            

Reported by PMD.