Ignore:
Timestamp:
May 10, 2007, 8:00:44 PM (17 years ago)
Author:
mmc
Message:

Fixed the Rappture::encoding::is function to properly detect embedded
nulls within a string and classify the string as "binary".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tcl/src/RpEncodeTclInterface.cc

    r684 r725  
    7878
    7979int
    80 RpTclEncodingIs     (   ClientData cdata,
    81                         Tcl_Interp *interp,
    82                         int objc,
    83                         Tcl_Obj *const objv[]  )
     80RpTclEncodingIs (ClientData cdata, Tcl_Interp *interp,
     81    int objc, Tcl_Obj *const objv[])
    8482{
    85     const char* type     = NULL; // type of data being checked
    86     const char* buf      = NULL; // buffer to be checked
    87     const char* cmdName  = NULL;
    88 
    89     int typeLen          = 0;
    90     int bufLen           = 0; // length of user provided buffer
    91     int nextarg          = 0;  // next argument
    92 
    9383    Tcl_ResetResult(interp);
    94 
    95     cmdName = Tcl_GetString(objv[nextarg++]);
    9684
    9785    // parse through command line options
     
    9987        Tcl_AppendResult(interp,
    10088            "wrong # args: should be \"",
    101             cmdName," binary <string>\"",
     89            Tcl_GetString(objv[0])," binary <string>\"",
    10290            (char*)NULL);
    10391        return TCL_ERROR;
    10492    }
    10593
    106     type = Tcl_GetStringFromObj(objv[nextarg++],&typeLen);
    107     buf = Tcl_GetStringFromObj(objv[nextarg++],&bufLen);
    108 
    109     if (strncmp(type,"binary",typeLen) == 0) {
     94    const char *type = Tcl_GetString(objv[1]);
     95
     96    int bufLen;
     97    const char *buf = (const char*) Tcl_GetByteArrayFromObj(objv[2],&bufLen);
     98
     99    if (strcmp(type,"binary") == 0) {
    110100        if (Rappture::encoding::isbinary(buf,bufLen) != 0) {
    111101            // non-ascii character found, return yes
    112             Tcl_AppendResult(interp, "yes",(char*)NULL);
    113             return TCL_OK;
     102            Tcl_AppendResult(interp, "yes", (char*)NULL);
     103        } else {
     104            Tcl_AppendResult(interp, "no",(char*)NULL);
    114105        }
    115     }
    116     else {
    117         Tcl_AppendResult(interp, "bad option \"", type,
    118                 "\": should be binary",
    119                 (char*)NULL);
    120         return TCL_ERROR;
    121 
    122     }
    123 
    124     // default return
    125     // no binary characters found, return no
    126     Tcl_AppendResult(interp, "no",(char*)NULL);
    127     return TCL_OK;
     106        return TCL_OK;
     107    }
     108    Tcl_AppendResult(interp, "bad option \"", type,
     109            "\": should be binary",
     110            (char*)NULL);
     111    return TCL_ERROR;
    128112}
    129113
Note: See TracChangeset for help on using the changeset viewer.