{"record":{"id":"3b9b728427fce9be","repo":"krahets/hello-algo","slug":"error-3b9b72","errorCode":null,"errorMessage":"頂点インデックスが範囲外です\n","messagePattern":"頂点インデックスが範囲外です\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/codes/c/chapter_graph/graph_adjacency_matrix.c","lineNumber":54,"sourceCode":"/* 頂点を追加 */\nvoid addVertex(GraphAdjMat *graph, int val) {\n    if (graph->size == MAX_SIZE) {\n        fprintf(stderr, \"グラフの頂点数が最大値に達しました\\n\");\n        return;\n    }\n    // n 番目の頂点を追加し、n 行目と n 列目を 0 にする\n    int n = graph->size;\n    graph->vertices[n] = val;\n    for (int i = 0; i <= n; i++) {\n        graph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n    }\n    graph->size++;\n}\n\n/* 頂点を削除 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\n    if (index < 0 || index >= graph->size) {\n        fprintf(stderr, \"頂点インデックスが範囲外です\\n\");\n        return;\n    }\n    // 頂点リストから index の頂点を削除する\n    for (int i = index; i < graph->size - 1; i++) {\n        graph->vertices[i] = graph->vertices[i + 1];\n    }\n    // 隣接行列で index 行を削除する\n    for (int i = index; i < graph->size - 1; i++) {\n        for (int j = 0; j < graph->size; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i + 1][j];\n        }\n    }\n    // 隣接行列で index 列を削除する\n    for (int i = 0; i < graph->size; i++) {\n        for (int j = index; j < graph->size - 1; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i][j + 1];\n        }\n    }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/c/chapter_graph/graph_adjacency_matrix.c#L36-L72","documentation":"Japanese localization of the removeVertex bounds check (see error 601). The graph indexes vertices by position in a contiguous array, so an index outside [0, graph->size) is rejected. The function logs to stderr and returns void with no status code.","triggerScenarios":"removeVertex(graph, index) with index < 0 or index >= graph->size — e.g. a stale index used after a prior deletion shifted vertices left.","commonSituations":"Cached indices going stale across mutations; confusing a vertex value with its array index; deleting inside a loop with a counter used as index.","solutions":["Verify 0 <= index && index < graph->size before the call.","Recompute cached indices after each deletion (higher indices shift down).","Look up the index by scanning vertices[] when you only have the value."],"exampleFix":"// before\nremoveVertex(graph, 5);   // size == 5 -> out of bounds\n\n// after\nif (graph->size > 0) removeVertex(graph, graph->size - 1);","handlingStrategy":"validation","validationCode":"static inline int graphValidIndex(const GraphAdjMat *g, int idx) {\n    return g != NULL && idx >= 0 && idx < g->size;\n}\n\nif (graphValidIndex(graph, index)) removeVertex(graph, index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not cache indices across mutations; re-derive from vertices[].","Distinguish values from indices in naming and reasoning.","Track that deletions shift higher indices down by one."],"tags":["graph","bounds","index","adjacency-matrix","c","i18n-ja"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}