Tag: 正确性

安全地添加整数,并certificate安全性

编程课程作业要求 写一个(安全)函数,添加两个整数,和 表明该function是安全的。 以下代码代表我的解决方案。 我不是C标准(或正式validation方法)的专家。 所以我想问:有更好(或不同)的解决方案吗? 谢谢 #include /* Try to add integers op1 and op2. Return 0 (success) or 1 (overflow prevented). In case of success, write the sum to res. */ int safe_int_add(int * res, int op1, int op2) { if (op2 op2 */ /* 0 < – op2 */ /* INT_MIN < […]