在这个生成函数接收外部数量之前进行审查。
在最多 16 个整数中查找首个落入闭区间 [low, high] 的值。拒绝空输出指针,不得访问 count 之外的位置,并在所有失败路径上保持 *out 不变。
C
int find_between(const int values[16],
size_t count,
int low,
int high,
const int **out) {
*out = NULL;
if (low > high) {
return 0;
}
for (size_t index = 0; index <= count; ++index) {
if (values[index] > low && values[index] < high) {
*out = &values[index];
return 1;
}
}
return 0;
}
生成代码仅作示例,不代表任何特定模型