Hello,

I found another bug in owtcl.

Tcl does UTF mangling on the result of Tcl_GetStringFromObj. This is
very disturbing for the value of a "put" operation as there is no way to
output binary data to owfs as it is possible with owfs/fuse itself (and
the other language bindings, I guess).

As far as I see there is no use case for such a mangling. The onewire
devices expect mostly numbers or binary data, the only device expecting
text is the LCD, and this is *not* UTF but another encoding.

Comments welcome.



Index: module/owtcl/ow.c
===================================================================
RCS file: /cvsroot/owfs/owfs/module/owtcl/ow.c,v
retrieving revision 1.5
diff -u -r1.5 ow.c
--- module/owtcl/ow.c   23 Sep 2010 03:17:16 -0000      1.5
+++ module/owtcl/ow.c   23 Jun 2013 20:38:12 -0000
@@ -259,8 +259,9 @@
 owtcl_ObjCmdProc(Owtcl_Put)
 {
        OwtclStateType *OwtclStatePtr = (OwtclStateType *) clientData;
-       char *path, *value;
-       int path_len, value_len, r;
+       char *path, *value=NULL;
+       Tcl_UniChar *uvalue;
+       int path_len, value_len, r, v;
        int tcl_return = TCL_OK;
        owtcl_ArgObjIncr;

@@ -270,11 +271,19 @@
                tcl_return = TCL_ERROR;
                goto common_exit;
        }
-       if (objc == 3)
-               value = Tcl_GetStringFromObj(objv[2], &value_len);
+       if (objc == 3) {
+               uvalue = Tcl_GetUnicodeFromObj(objv[2], &value_len);
+               value = malloc(value_len);
+               if (value != NULL)
+                       for (v=0 ; v < value_len ; v++)
+                               value[v]=(char)uvalue[v];
+       }
        else {
-               value = "\n";
-               value_len = 1;
+               value=malloc(1);
+               if (value != NULL) {
+                       value[0] = '\n';
+                       value_len = 1;
+               }
        }

        /* Check we are connected to onewire host(s). */
@@ -293,6 +302,7 @@
        }

   common_exit:
+       free(value);
        owtcl_ArgObjDecr;
        return tcl_return;
 }


Kind regards

        Jan

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to