#include "hbytes.h"
#include "tables.h"
-int staticerr(Tcl_Interp *ip, const char *m) {
+int staticerr(Tcl_Interp *ip, const char *m, const char *ec) {
Tcl_SetResult(ip, (char*)m, TCL_STATIC);
+ if (ec) Tcl_SetObjErrorCode(ip, Tcl_NewStringObj(ec,-1));
return TCL_ERROR;
}
objfreeir(o);
if (l & 1) return staticerr(ip, "hbytes: conversion from hex:"
- " odd length in hex");
+ " odd length in hex", "HBYTES SYNTAX");
startbytes= bytes= hbytes_arrayspace(OBJ_HBYTES(o), l/2);
if (ep != cbuf+2) {
hbytes_free(OBJ_HBYTES(o));
return staticerr(ip, "hbytes: conversion from hex:"
- " bad hex digit");
+ " bad hex digit", "HBYTES SYNTAX");
}
l -= 2;
}
sub_l= hbytes_len(&sub);
if (start < 0)
- return staticerr(ip, "hbytes overwrite start -ve");
+ return staticerr(ip, "hbytes overwrite start -ve",
+ "HBYTES LENGTH RANGE");
if (start + sub_l > hbytes_len(v.hb))
- return staticerr(ip, "hbytes overwrite out of range");
+ return staticerr(ip, "hbytes overwrite out of range",
+ "HBYTES LENGTH UNDERRUN");
memcpy(hbytes_data(v.hb) + start, hbytes_data(&sub), sub_l);
return TCL_OK;
}
const Byte *sub_d;
sub_l= hbytes_len(&sub);
- if (count < 0) return staticerr(ip, "hbytes repeat count -ve");
- if (count > INT_MAX/sub_l) return staticerr(ip, "hbytes repeat too long");
+ if (count < 0) return staticerr(ip, "hbytes repeat count -ve",
+ "HBYTES LENGTH RANGE");
+ if (count > INT_MAX/sub_l) return staticerr(ip, "hbytes repeat too long", 0);
data= hbytes_arrayspace(result, sub_l*count);
sub_d= hbytes_data(&sub);
int l;
l= hbytes_len(&v);
- if (start<0 || size<0 || l<start+size)
- return staticerr(ip, "hbytes range subscripts out of range");
+ if (start<0 || size<0)
+ return staticerr(ip,"hbytes range subscript(s) -ve","HBYTES LENGTH RANGE");
+ if (l<start+size)
+ return staticerr(ip, "hbytes range subscripts too big",
+ "HBYTES LENGTH UNDERRUN");
data= hbytes_data(&v);
hbytes_array(result, data+start, size);
l= hbytes_len(&hex);
if (l>2)
- return staticerr(ip, "hbytes h2ushort input more than 4 hex digits");
+ return staticerr(ip, "hbytes h2ushort input more than 4 hex digits",
+ "HBYTES VALUE OVERFLOW");
data= hbytes_data(&hex);
*result= data[l-1] | (l>1 ? data[0]<<8 : 0);
uint16_t us;
if (input > 0x0ffff)
- return staticerr(ip, "hbytes ushort2h input >2^16");
+ return staticerr(ip, "hbytes ushort2h input >2^16",
+ "HBYTES VALUE OVERFLOW");
us= htons(input);
hbytes_array(result,(const Byte*)&us,2);
return posixerr(ip,errno,"read " URANDOM);
} else {
assert(feof(urandom));
- return staticerr(ip, URANDOM " gave eof!");
+ return staticerr(ip, URANDOM " gave eof!", 0);
}
}