avoid-scanf-for-char-input
Use when using scanf() to read a single character into an integer variable
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use when using scanf() to read a single character into an integer variable
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 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
| name | avoid-scanf-for-char-input |
| description | Use when using scanf() to read a single character into an integer variable |
A KLEE-coverage code transformation. Applying it rewrites C source so symbolic execution explores more of the program's behavior.
When using scanf() to read a single character into an integer variable
Replace scanf("%c", &int_var) with getchar() and use char type instead of int for character operations
scanf with %c format on int variables creates complex symbolic constraints due to type mismatches and format string parsing overhead, while getchar() with char type produces simpler constraints that KLEE can solve more efficiently
Before:
#include<stdio.h>
int main() {
int a;
int b;
scanf("%c",&a);
b=++a;
printf("%c",b);
}
After:
#include<stdio.h>
int main()
{
char c1;
c1=getchar();
putchar(c1+1);
putchar('\n');
return 0;
}
645ca7c5