fix(crc): CRC_make_crc_32_table が table[255] を初期化しない#486
Merged
Conversation
The 32-bit table generator looped `for (i = 0; i < 255; ++i)`, leaving table[255] uninitialized, while the 8-bit and 16-bit variants correctly loop to 256. crc.h documents the table as 256 entries. Any CRC-32 over a byte ending in 0xff would have used a garbage table entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
CRC_make_crc_32_table のテーブル生成ループが i < 255 になっていたため table[255] が未初期化となる不具合を修正し、CRC-32 テーブルが 256 要素すべて初期化されるようにする PR です(crc.h の「sizeof(table) = 256」および CRC-8/16 実装と整合)。
Changes:
CRC_make_crc_32_tableの生成ループ条件をi < 255→i < 256に修正し、table[255]を確実に初期化
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Toshifumi Akima (ToshiAki64)
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
CRC_make_crc_32_tableの生成ループがfor (i = 0; i < 255; ++i)になっており、table[255]が未初期化のまま残る。8bit版・16bit版はどちらもi < 256であり、crc.hのコメントも「sizeof(table) = 256」と明記している。影響
CRC_make_crc_32_tableの呼び出し元はリポジトリ内にゼロのため実害は出ていない。修正
i < 255→i < 256。検証
実ソース
library/crc.cをそのままコンパイルした再現プログラムで確認:table[255] = 0x2d02ef8d(標準 CRC-32 テーブルの正規値)備考
library/の葉関数なので本来は unit test を付けたいが、C コードの unit test 実行基盤は #473 で導入予定。本PRは1行修正のみとし、リグレッションテストは #473 マージ後に同基盤上へ追加する。🤖 Generated with Claude Code