arithmetic-over-char-iteration
Use when loop variables iterate over character values (e.g., ASCII codes) to represent different operations or choices
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Use when loop variables iterate over character values (e.g., ASCII codes) to represent different operations or choices
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Use 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 code uses a loop to search for an input value in an array and then uses the found index for further computation
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
| name | arithmetic-over-char-iteration |
| description | Use when loop variables iterate over character values (e.g., ASCII codes) to represent different operations or choices |
A KLEE-coverage code transformation. Applying it rewrites C source so symbolic execution explores more of the program's behavior.
When loop variables iterate over character values (e.g., ASCII codes) to represent different operations or choices
Replace character-based iteration with integer indices into an array that maps to the desired values or operations
KLEE handles integer constraints more efficiently than character arithmetic constraints, and array indexing with simple integer bounds creates cleaner path conditions that are easier for the constraint solver to reason about
Before:
#include<stdio.h>
char str[8];
int a,b,c,d;
int main(void){
register int i,j,k,ans;
gets(str);
a=str[0]-'0';b=str[1]-'0';c=str[2]-'0';d=str[3]-'0';
for(i='+';i<='-';i+=2)
for(j='+';j<='-';j+=2)
for(k='+';k<='-';k+=2){
ans=a;
if(i=='+')
ans+=b;
else
ans-=b;
if(j=='+')
ans+=c;
else
ans-=c;
if(k=='+')
ans+=d;
else
ans-=d;
if(ans==7)
return printf("%d%c%d%c%d%c%d=7\n",a,i,b,j,c,k,d),0;
}
return 0;
}
After:
#include <stdio.h>
int math[]={-1,1};
int main()
{
int a[4];register int i,j,k;
for(i=0; i<4; ++i)
{
char c=getchar();
a[i]=c-'0';
}
for (i=0; i<2; ++i)
for (j=0; j<2; ++j)
for (k=0; k<2; ++k)
if(a[0]+math[i]*a[1]+math[j]*a[2]+math[k]*a[3]==7)
{
printf("%d",a[0]);
printf("%c",i==0?'-':'+');
printf("%d",a[1]);
printf("%c",j==0?'-':'+');
printf("%d",a[2]);
printf("%c",k==0?'-':'+');
printf("%d",a[3]);
printf("=7\n");
return 0;
}
}
52bc8f21