avoid-modulo-operations
Use when code uses modulo operator (%) to extract digits or parts of a number
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when code uses modulo operator (%) to extract digits or parts of a number
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | avoid-modulo-operations |
| description | Use when code uses modulo operator (%) to extract digits or parts of a number |
A KLEE-coverage code transformation. Applying it rewrites C source so symbolic execution explores more of the program's behavior.
When code uses modulo operator (%) to extract digits or parts of a number
Replace modulo operations with equivalent arithmetic using subtraction and multiplication (e.g., replace 'a%100' with 'a-100*(a/100)')
Modulo operations create more complex symbolic expressions in KLEE, making constraint solving harder and potentially limiting path exploration, while arithmetic operations with multiplication and subtraction produce simpler constraints
Before:
#include<stdio.h>
int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}
}
After:
#include<stdio.h>
int main()
{
int a, b, c, d, e;
scanf("%d", &e);
a=e/100;
b=e-100*a;
if(a>=1&&a<=12)
{
if(b>=1&&b<=12)
printf("AMBIGUOUS");
else
printf("MMYY");
}
else
{
if(b>=1&&b<=12)
printf("YYMM");
else
printf("NA");
}
}
0e7743ccUse 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 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