@@ -404,28 +404,15 @@ export class FuzzedDataProvider {
404
404
return result ;
405
405
}
406
406
407
- /**
408
- * Wrapping subtraction function that returns a number within a set limit
409
- * @param min is a number representing the minuend
410
- * @param sub is a number representing the subtrahend
411
- * @param lim sets the upper boundary
412
- * @returns a number n with the constraint 0 <= n < lim, as long as lim >=2
413
- */
414
- wrappingSub ( min : number , sub : number , lim : number ) : number {
415
- if ( lim < 2 ) {
416
- throw new Error ( "Upper boundary should be greater than or equal to 2" ) ;
417
- }
418
- return ( min - sub + lim ) % lim ;
419
- }
420
-
421
407
/**
422
408
* A simple conversion helper that yields the ASCII representaion of a character.
423
409
* @param char is a single character from a string represented as a number
424
410
* @returns a 'string' from a single character that was represented by a number
425
411
*/
426
412
toAscii ( char : number ) : number {
427
413
if ( char < 32 || char > 126 ) {
428
- char = ( this . wrappingSub ( char , 32 , 255 ) % 95 ) + 32 ;
414
+ const moduloInRange = ( char - 32 + 256 ) % 256 ;
415
+ return ( moduloInRange % 95 ) + 32 ;
429
416
}
430
417
return char ;
431
418
}
@@ -436,6 +423,8 @@ export class FuzzedDataProvider {
436
423
* (non-smart) but printable strings, IFF the entropy of the input buffer is
437
424
* high enough. Limitations are that there are collisions such that, e.g.:
438
425
* the conversion of values: `0x1`, `0x42`, and `0xa2` all yield the character `B`.
426
+ * Elements in `buf` that are already in ASCII printable range are not undergoing
427
+ * any conversion.
439
428
* @param buf - Buffer that contains arbitrary values
440
429
* @param min - lower bound at which processing of the provided `Buffer` shall begin
441
430
* @param max - upper bound, analogous to the lower bound
0 commit comments