mattiasw2 / teyjus

Automatically exported from code.google.com/p/teyjus
GNU General Public License v3.0
0 stars 0 forks source link

incorrect size of substring #88

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Those steps will reproduce the problem:
1. start tjsim
2. Enter the following query:
  X is substring "12345" 2 3, Y is size X.

You will get the following output:
  The answer substitution:
  Y = 4
  X = "345"

The expected output is:
  Y = 3
  X = "345"

The size of the substring should always be the length of the substring without 
the terminating '\0' character.

Version of the simulator:
Teyjus version 2.0-b2
on Ubuntu 12.04.4 LTS

To fix this, you could apply the following patch to the function 
MCSTR_subString in the file source/simulator/mcstring.c. Most tests seem to be 
okay after applying the patch except for exportdef.t, but maybe that's another 
issue.

$ svn diff
Index: mcstring.c
===================================================================
--- mcstring.c  (revision 1136)
+++ mcstring.c  (working copy)
@@ -84,7 +84,7 @@
     char* fromPtr = ((char*)(str + 1))+startPos;
     char* toPtr   = (char*)(loc + 1);

-    *((int *)loc) = (length + 1);
+    *((int *)loc) = length;
     while (length > 0) {
       *toPtr++ = *fromPtr++;
       length--;

Original issue reported on code.google.com by alf42...@gmail.com on 28 Jun 2014 at 5:27

GoogleCodeExporter commented 9 years ago
Thanks, it's fixed!

The failure for exportdef.t is unrelated (I added the test case but I don't 
know how to fix it).

Original comment by fafounet@gmail.com on 16 Jul 2014 at 3:27