search-division

Scans C/C++ source files for division operations and replaces divide-by-zero risks with a safe template.

Updated May 28, 2026
One-click install
npx skills add https://github.com/HPI-Jimmy-Chiu/HT904_V899 --skill search-division-hpi-jimmy-chiu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: search-division
Source: https://github.com/HPI-Jimmy-Chiu/HT904_V899/tree/main/.agents/skills/search-division
Command: npx skills add https://github.com/HPI-Jimmy-Chiu/HT904_V899 --skill search-division-hpi-jimmy-chiu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Legacy C/C++ codebases often contain unguarded division operations that crash when the divisor is zero. Manually finding, assessing, and rewriting every division across hundreds of .cpp files is slow and error-prone, especially in Big5-encoded BCB6 projects. ## Core Features & Use Cases - Division Discovery: Scans all .cpp files with regex-based filtering that skips comments, string literals, preprocessor directives, and C++ keywords, producing a candidate CSV. - Risk Filtering: Analyzes 20 lines of surrounding context to exclude divisions already protected by if-checks, ternary guards, constant divisors, or existing safe-template calls. - Automated Replacement: Generates Old-to-New expression pairs and applies them bottom-up using Big5/CP950 encoding, wrapping risky divisions in the ChangeToFloatNonPcnt safe template. - Post-Replacement Verification: Detects and auto-repairs two known corruption patterns (member-function misplacement and function-argument separation), then produces a Traditional Chinese report. - Use Case: A maintainer of a BCB6 machine-control project needs to harden 300 division sites against divide-by-zero crashes before release; the skill scans, filters, replaces, verifies, and reports in one workflow. ## Quick Start Ask the AI to scan the project directory for all division operations, filter out the ones already protected against zero divisors, and replace the risky ones with the ChangeToFloatNonPcnt safe template.

Frequently Asked Questions about search-division

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find all division by zero risks in C++ code?▼

Run the find_divisions.ps1 PowerShell script against your project directory to scan all .cpp files for division operations. It filters out comments, string literals, and preprocessor lines, then outputs a CSV of candidate divisions with file, line, and divisor information.

How to automatically replace unsafe division in C++ with a safe template?▼

After filtering risky divisions, the generate_replacements.ps1 script parses each numerator and denominator and creates replacement pairs wrapping them in ChangeToFloatNonPcnt. The apply_replacements.ps1 script then rewrites the files bottom-up using Big5/CP950 encoding.

Does the scan skip divisions that already have zero checks?▼

Yes. The filtering stage examines 20 lines of context around each division and excludes those protected by if(var!=0) conditions, ternary guards, non-zero constant assignments, or existing ChangeToFloat template calls. OR-conditions like if(A>0 || B>0) are still treated as risky.

Why does the replacement produce broken code like .ChangeToFloatNonPcnt?▼

This happens when numerator back-scanning misses an object prefix such as MOT[x]., or when a function-call divisor loses its arguments. The verify_replacements.ps1 script in phase 3.5 automatically detects and repairs both corruption patterns.

Can I exclude specific constant divisors from replacement?▼

Yes. Edit the $skipDivisors list in generate_replacements.ps1 to name compile-time constants such as MAX_SOCKET_ROW that are guaranteed non-zero. Matching divisions are skipped and documented in the final report.