chiark / gitweb /
use of int and overflow review
[chiark-tcl.git] / base / hook.c
index acd708a91f5cb92e2910e1656881300e9a9b7f32..cc3eba867eaf9111e62bab013376f724aee53334 100644 (file)
@@ -53,11 +53,15 @@ void cht_obj_updatestr_vstringls(Tcl_Obj *o, ...) {
   va_list al;
   char *p;
   const char *part;
-  int l, pl;
+  int l;
+  size_t pl;
 
   va_start(al,o);
-  for (l=0; (part= va_arg(al, const char*)); )
-    l+= va_arg(al, int);
+  for (l=0; (part= va_arg(al, const char*)); ) {
+    pl= va_arg(al, size_t);
+    assert(pl <= INT_MAX/2 - l);
+    l += pl;
+  }
   va_end(al);
   
   o->length= l;
@@ -65,7 +69,7 @@ void cht_obj_updatestr_vstringls(Tcl_Obj *o, ...) {
 
   va_start(al,o);
   for (p= o->bytes; (part= va_arg(al, const char*)); p += pl) {
-    pl= va_arg(al, int);
+    pl= va_arg(al, size_t);
     memcpy(p, part, pl);
   }
   va_end(al);
@@ -102,34 +106,21 @@ int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l) {
   }
 }
 
-int cht_initextension(Tcl_Interp *ip, const TopLevel_Command *cmds,
-                       int *donep /* or 0, meaning no types follow */,
-                       ... /* types, terminated by 0 */) {
-  static int cht_initd;
-
-  const TopLevel_Command *cmd;
-  Tcl_ObjType *ot;
-
-  va_list al;
-
-  if (!cht_initd) {
-    cht_initd= 1;
-    Tcl_RegisterObjType(&cht_tabledataid_nearlytype);
-    Tcl_RegisterObjType(&cht_enum_nearlytype);
-    Tcl_RegisterObjType(&cht_enum1_nearlytype);
-  }
+void cht_prepare__basic(Tcl_Interp *ip) {
+  static int prepared;
 
-  if (donep && !*donep) {
-    *donep= 1;
-    va_start(al, donep);
-    while ((ot= va_arg(al, Tcl_ObjType*)))
-      Tcl_RegisterObjType(ot);
-  }
+  if (prepared) return;
+  Tcl_RegisterObjType(&cht_tabledataid_nearlytype);
+  Tcl_RegisterObjType(&cht_enum_nearlytype);
+  Tcl_RegisterObjType(&cht_enum1_nearlytype);
+  prepared= 1;
+}
 
+void cht_setup__commands(Tcl_Interp *ip, const TopLevel_Command *cmds) {
+  const TopLevel_Command *cmd;
+  
   for (cmd= cmds;
        cmd->name;
        cmd++)
     Tcl_CreateObjCommand(ip, (char*)cmd->name, cmd->func, 0,0);
-
-  return TCL_OK;
 }