{"record":{"id":"5dea2ef14948f606","repo":"krahets/hello-algo","slug":"error-5dea2e","errorCode":null,"errorMessage":"индекс вершины выходит за границы\n","messagePattern":"индекс вершины выходит за границы\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/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    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/ru/codes/c/chapter_graph/graph_adjacency_matrix.c#L36-L72","documentation":"Russian localization of the removeVertex bounds check (see error 601). Vertices are positional in a contiguous array, so an index outside [0, graph->size) is rejected; stderr is written and the function returns void with no status.","triggerScenarios":"removeVertex(graph, index) with index < 0 or index >= graph->size — typically a stale index after a prior deletion.","commonSituations":"Stale cached indices; value/index confusion; in-loop deletion with a counter index.","solutions":["Guard with 0 <= index && index < graph->size.","Recompute indices after deletions.","Scan vertices[] to map a value to its current index."],"exampleFix":"// before\nremoveVertex(graph, 5);   // size == 5\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.","Separate values from indices in naming.","Account for the down-shift of higher indices after a deletion."],"tags":["graph","bounds","index","adjacency-matrix","c","i18n-ru"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}