[Cryptography] It's all K&R's fault

Patrick Chkoreff patrick at rayservers.net
Sun Apr 20 08:45:34 EDT 2014


Sampo Syreeni wrote, On 04/19/2014 08:38 PM:

> On 2014-04-19, Patrick Chkoreff wrote:
> 
>> Or just avoid the dangerous stuff and write your own bounds-checked
>> functions in C:
>>
>> https://github.com/chkoreff/Fexl/blob/fresh/src/str.c#L45
> 
> Don't do either. Get an intelligent compiler for an intelligent
> language, which inserts the bound checks when needed, and optimizes them
> away when possible. Win-win.

Well, the irony is that I'm using it only for the purpose of
implementing an intelligent language (Fexl) which always checks memory
bounds no matter what.

I even leave bounds checking enabled in extremely low-level code, such
as in this fast buffering routine:

https://github.com/chkoreff/Fexl/blob/fresh/src/buf.c#L36

I benchmarked buffering up a 2.6 GB string, one character at a time,
with and without that bounds checking assertion, and I saw no
statistically significant difference in run time.

I could of course "prove" that the bounds check was unnecessary and thus
remove it, but it would make the code less fault-tolerant.


-- Patrick



More information about the cryptography mailing list