MOD by zero bug

Issue #90 new
陈翔翔 created an issue

When using the MOD operator for arithmetic, we found that OpenPLC passed compilation while MOD by zero.

We first created a new project, then selected the language as ST and named the main program as MAIN. Then we declared the variables i and A, and initialized them to zero respectively, and added the code "A := 5 MOD 0;" in the runtime section. Finally, follow the steps of clicking the Build button, connecting to the target PLC, transferring PLC and starting PLC. We found that the program passed the compilation without any error message.

#------------------------------------------------------------------
#ST Program:
PROGRAM MAIN
  VAR
    i : INT := 0;
    A : INT := 0;
  END_VAR

  A := 5 MOD 0;
END_PROGRAM

#------------------------------------------------------------------
#Returned Message:
Start build in /root/MOD0/build
Generating SoftPLC IEC-61131 ST/IL/SFC code...
    Collecting data types
    Collecting POUs
    Generate POU MAIN
    Generate Config(s)
Compiling IEC Program into C code...
Extracting Located Variables...
C code generated successfully.
PLC :
   [pass]  plc_main.c -> plc_main.o
   [pass]  plc_debugger.c -> plc_debugger.o
py_ext :
   [pass]  py_ext.c -> py_ext.o
PLC :
   [pass]  config.c -> config.o
   [CC]  resource1.c -> resource1.o
Linking :
   [CC]  plc_main.o plc_debugger.o py_ext.o config.o resource1.o -> MOD0.so
Successfully built.
Latest build does not match with connected target.
PLC data transfered successfully.
PLC installed successfully.
Starting PLC

The running result of Editor downloaded from the official website of openplc

The running result of BeremizIDE downloaded from this website according to the tutorial:

This issue has been copied to the issue under metic_git.

Comments (1)

  1. Log in to comment