@@ -346,9 +346,11 @@ SEXP RTcl_ObjAsCharVector(SEXP args)
346346 obj = (Tcl_Obj * ) R_ExternalPtrAddr (CADR (args ));
347347 if (!obj ) error (_ ("invalid tclObj -- perhaps saved from another session?" ));
348348 ret = Tcl_ListObjGetElements (RTcl_interp , obj , & count , & elem );
349- if (ret != TCL_OK || count > R_XLEN_T_MAX )
349+ if (ret != TCL_OK )
350350 return RTcl_StringFromObj (args );
351-
351+ if (sizeof (Tcl_Size ) > sizeof (R_xlen_t ) && count > R_XLEN_T_MAX )
352+ return RTcl_StringFromObj (args );
353+
352354 PROTECT (ans = allocVector (STRSXP , (R_xlen_t ) count ));
353355 for (i = 0 ; i < count ; i ++ ) {
354356 char * s ;
@@ -427,9 +429,11 @@ SEXP RTcl_ObjAsDoubleVector(SEXP args)
427429
428430 /* Then try as list */
429431 ret = Tcl_ListObjGetElements (RTcl_interp , obj , & count , & elem );
430- if (ret != TCL_OK || count > R_XLEN_T_MAX ) /* didn't work, return NULL */
432+ if (ret != TCL_OK ) /* didn't work, return NULL */
431433 return R_NilValue ;
432-
434+ if (sizeof (Tcl_Size ) > sizeof (R_xlen_t ) && count > R_XLEN_T_MAX )
435+ return R_NilValue ;
436+
433437 ans = allocVector (REALSXP , (R_xlen_t ) count );
434438 for (i = 0 ; i < count ; i ++ ){
435439 ret = Tcl_GetDoubleFromObj (RTcl_interp , elem [i ], & x );
@@ -492,9 +496,11 @@ SEXP RTcl_ObjAsIntVector(SEXP args)
492496
493497 /* Then try as list */
494498 ret = Tcl_ListObjGetElements (RTcl_interp , obj , & count , & elem );
495- if (ret != TCL_OK || count > R_XLEN_T_MAX ) /* didn't work, return NULL */
499+ if (ret != TCL_OK ) /* didn't work, return NULL */
496500 return R_NilValue ;
497-
501+ if (sizeof (Tcl_Size ) > sizeof (R_xlen_t ) && count > R_XLEN_T_MAX )
502+ return R_NilValue ;
503+
498504 ans = allocVector (INTSXP , (R_xlen_t ) count );
499505 for (i = 0 ; i < count ; i ++ ){
500506 ret = Tcl_GetIntFromObj (RTcl_interp , elem [i ], & x );
@@ -549,7 +555,8 @@ SEXP RTcl_ObjAsRawVector(SEXP args)
549555 /* Then try as list */
550556 if (Tcl_ListObjGetElements (RTcl_interp , obj , & count , & elem )
551557 != TCL_OK ) return R_NilValue ;
552- if (count > R_XLEN_T_MAX ) return R_NilValue ;
558+ if (sizeof (Tcl_Size ) > sizeof (R_xlen_t ) && count > R_XLEN_T_MAX )
559+ return R_NilValue ;
553560
554561 PROTECT (ans = allocVector (VECSXP , (R_xlen_t ) count ));
555562 for (i = 0 ; i < count ; i ++ ) {
0 commit comments