array-lookup-to-explicit-branches
Use when code uses a loop to search for an input value in an array and then uses the found index for further computation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when code uses a loop to search for an input value in an array and then uses the found index for further computation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | array-lookup-to-explicit-branches |
| description | Use when code uses a loop to search for an input value in an array and then uses the found index for further computation |
A KLEE-coverage code transformation. Applying it rewrites C source so symbolic execution explores more of the program's behavior.
When code uses a loop to search for an input value in an array and then uses the found index for further computation
Replace the array search loop with explicit if-else branches that directly map each possible input value to its corresponding output value
KLEE can more easily explore all paths when conditions are explicit branches rather than loop iterations with array indexing, reducing the complexity of symbolic constraints
Before:
#include<stdio.h>
int main(void){
char a[2];
char b[]="ACGT";
int i,j=0;
scanf("%c",a);
for(i=0;i<4;i++){
if(a[0]==b[i]) j=i;
}
printf("%c\n",b[3-j]);
return 0;
}
After:
#include<stdio.h>
char c;
int main()
{
c=getchar();
if(c=='A')c='T';
else if(c=='G')c='C';
else if(c=='T')c='A';
else if(c=='C')c='G';
putchar(c);
}/**/
6bbea5eaUse when printf statements output strings without trailing newlines
Use when array is accessed with direct user input as index (0-based indexing)
Use when the program accesses a precomputed table using an offset (e.g., arr[n-1]) that introduces an arithmetic operation between the symbolic input and the index
Use when loop variables iterate over character values (e.g., ASCII codes) to represent different operations or choices
Use when code reads a fixed number of characters into an array and only accesses individual elements
Use when code uses an array to store a single character/value that is only accessed at one index