added parameter checking to `sc_right_trim`

fixes conversion from 'size_t' to 'long', possible loss of data
This commit is contained in:
Frank Morgner 2016-06-05 21:18:38 +02:00
parent 836842a6bb
commit 050c62f7df
1 changed files with 12 additions and 7 deletions

View File

@ -126,15 +126,20 @@ int sc_bin_to_hex(const u8 *in, size_t in_len, char *out, size_t out_len,
*/
size_t sc_right_trim(u8 *buf, size_t len) {
long i;
size_t i;
for(i=len-1; i >=0; i--) {
if(!isprint(buf[i])) {
buf[i] = '\0';
len--;
continue;
if (!buf)
return 0;
if (len > 0) {
for(i = len-1; i > 0; i--) {
if(!isprint(buf[i])) {
buf[i] = '\0';
len--;
continue;
}
break;
}
break;
}
return len;
}