[gimp] String-ref, string-set!, vector-ref, and vector-set! index must be integer.



commit 53b7a0935e0c179679316d465c1638e18b0044d5
Author: Kevin Cozens <kevin ve3syb ca>
Date:   Sun Aug 2 21:29:15 2020 -0400

    String-ref, string-set!, vector-ref, and vector-set! index must be integer.
    
    R5RS compliance fix. From bug #42 reported in the SourgeForge bug tracker.

 plug-ins/script-fu/tinyscheme/scheme.c | 40 ++++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/script-fu/tinyscheme/scheme.c b/plug-ins/script-fu/tinyscheme/scheme.c
index 8b242d5d6d..a5b1b02c22 100644
--- a/plug-ins/script-fu/tinyscheme/scheme.c
+++ b/plug-ins/script-fu/tinyscheme/scheme.c
@@ -3636,14 +3636,19 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
 
      case OP_STRREF: { /* string-ref */
           char *str;
+          pointer x;
           int index;
 
           str=strvalue(car(sc->args));
 
-          index=ivalue(cadr(sc->args));
+          x=cadr(sc->args);
+          if (!is_integer(x)) {
+               Error_1(sc,"string-ref: index must be exact:",x);
+          }
 
+          index=ivalue(x);
           if(index>=g_utf8_strlen(strvalue(car(sc->args)), -1)) {
-               Error_1(sc,"string-ref: out of bounds:",cadr(sc->args));
+               Error_1(sc,"string-ref: out of bounds:",x);
           }
 
           str = g_utf8_offset_to_pointer(str, (long)index);
@@ -3669,9 +3674,15 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
           }
 
           str=strvalue(a);
-          index=ivalue(cadr(sc->args));
-          if(index>=g_utf8_strlen(str, -1)) {
-              Error_1(sc,"string-set!: out of bounds:",cadr(sc->args));
+
+          x=cadr(sc->args);
+          if (!is_integer(x)) {
+               Error_1(sc,"string-set!: index must be exact:",x);
+          }
+
+          index=ivalue(x);
+          if(index>=strlength(car(sc->args))) {
+               Error_1(sc,"string-set!: out of bounds:",x);
           }
 
           c=charvalue(caddr(sc->args));
@@ -3824,27 +3835,38 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
           s_return(sc,mk_integer(sc,ivalue(car(sc->args))));
 
      case OP_VECREF: { /* vector-ref */
+          pointer x;
           int index;
 
-          index=ivalue(cadr(sc->args));
+          x=cadr(sc->args);
+          if (!is_integer(x)) {
+               Error_1(sc,"vector-ref: index must be exact:",x);
+          }
+          index=ivalue(x);
 
           if(index>=ivalue(car(sc->args))) {
-               Error_1(sc,"vector-ref: out of bounds:",cadr(sc->args));
+               Error_1(sc,"vector-ref: out of bounds:",x);
           }
 
           s_return(sc,vector_elem(car(sc->args),index));
      }
 
      case OP_VECSET: {   /* vector-set! */
+          pointer x;
           int index;
 
           if(is_immutable(car(sc->args))) {
                Error_1(sc,"vector-set!: unable to alter immutable vector:",car(sc->args));
           }
 
-          index=ivalue(cadr(sc->args));
+          x=cadr(sc->args);
+          if (!is_integer(x)) {
+               Error_1(sc,"vector-set!: index must be exact:",x);
+          }
+
+          index=ivalue(x);
           if(index>=ivalue(car(sc->args))) {
-               Error_1(sc,"vector-set!: out of bounds:",cadr(sc->args));
+               Error_1(sc,"vector-set!: out of bounds:",x);
           }
 
           set_vector_elem(car(sc->args),index,caddr(sc->args));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]