chiark / gitweb /
use of int and overflow review
[chiark-tcl.git] / hbytes / hook.c
index f3817ffe20d44de9c22029b270e554d650f0e44a..b2d4dc4e1abc657da57497315d8999b1795a2363 100644 (file)
@@ -67,12 +67,13 @@ static void hbytes_t_free(Tcl_Obj *o) {
   cht_hb_free(OBJ_HBYTES(o));
 }
 
-void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
+void cht_obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
                                int l, const char *prefix) {
   char *str;
   int pl;
 
   pl= strlen(prefix);
+  assert(l < INT_MAX/2 - 1 - pl);
   o->length= l*2+pl;
   str= o->bytes= TALLOC(o->length+1);
   
@@ -86,12 +87,12 @@ void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
   *str= 0;
 }
 
-void obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
-  obj_updatestr_array_prefix(o,byte,l,"");
+void cht_obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
+  cht_obj_updatestr_array_prefix(o,byte,l,"");
 }
 
 static void hbytes_t_ustr(Tcl_Obj *o) {
-  obj_updatestr_array(o,
+  cht_obj_updatestr_array(o,
                      cht_hb_data(OBJ_HBYTES(o)),
                      cht_hb_len(OBJ_HBYTES(o)));
 }
@@ -316,23 +317,6 @@ int cht_do_hbytes_ushort2h(ClientData cd, Tcl_Interp *ip,
 
 /* toplevel functions */
 
-int cht_do_hbytestoplevel_hbytes(ClientData cd, Tcl_Interp *ip,
-                      const HBytes_SubCommand *subcmd,
-                      int objc, Tcl_Obj *const *objv) {
-  return subcmd->func(0,ip,objc,objv);
-}
-
-int cht_do_hbytestoplevel_ulong(ClientData cd, Tcl_Interp *ip,
-                     const ULong_SubCommand *subcmd,
-                     int objc, Tcl_Obj *const *objv) {
-  return subcmd->func(0,ip,objc,objv);
-}
-
-int Chiark_tcl_hbytes_Init(Tcl_Interp *ip) {
-  static int initd;
-  
-  return cht_initextension(ip, cht_hbytestoplevel_entries, &initd,
-                          &cht_hbytes_type,
-                          &cht_ulong_type,
-                          (Tcl_ObjType*)0);
-}
+CHT_INIT(hbytes,
+        CHTI_TYPE(cht_hbytes_type) CHTI_TYPE(cht_ulong_type),
+        CHTI_COMMANDS(cht_hbytestoplevel_entries))