Skip to content

Commit e5dba34

Browse files
committed
🐛 修复矩阵快速转置中辅助数组容量分配的BUG
1 parent b9334c1 commit e5dba34

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

CLion/CourseBook/0502_TSMatrix/TSMatrix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ Status FastTransposeSMatrix(TSMatrix M, TSMatrix* T) {
379379
return ERROR;
380380
}
381381

382-
num = (int*) malloc(M.nu * sizeof(int));
383-
copt = (int*) malloc(M.nu * sizeof(int));
382+
num = (int*) malloc((M.nu + 1) * sizeof(int));
383+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
384384

385385
// 初始化数组num
386386
for(col = 1; col <= M.nu; ++col) {

CLion/CourseBook/0503_RLSMatrix/RLSMatrix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ Status FastTransposeSMatrix(RLSMatrix M, RLSMatrix* T) {
420420
return ERROR;
421421
}
422422

423-
num = (int*) malloc(M.nu * sizeof(int));
424-
copt = (int*) malloc(M.nu * sizeof(int));
423+
num = (int*) malloc((M.nu + 1) * sizeof(int));
424+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
425425

426426
// 初始化数组num
427427
for(col = 1; col <= M.nu; ++col) {

Dev-C++/CourseBook/0502_TSMatrix/TSMatrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ Status FastTransposeSMatrix(TSMatrix M, TSMatrix* T) {
379379
return ERROR;
380380
}
381381

382-
num = (int*) malloc(M.nu * sizeof(int));
383-
copt = (int*) malloc(M.nu * sizeof(int));
382+
num = (int*) malloc((M.nu + 1) * sizeof(int));
383+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
384384

385385
// 初始化数组num
386386
for(col = 1; col <= M.nu; ++col) {

Dev-C++/CourseBook/0503_RLSMatrix/RLSMatrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ Status FastTransposeSMatrix(RLSMatrix M, RLSMatrix* T) {
420420
return ERROR;
421421
}
422422

423-
num = (int*) malloc(M.nu * sizeof(int));
424-
copt = (int*) malloc(M.nu * sizeof(int));
423+
num = (int*) malloc((M.nu + 1) * sizeof(int));
424+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
425425

426426
// 初始化数组num
427427
for(col = 1; col <= M.nu; ++col) {

VisualC++/CourseBook/0502_TSMatrix/TSMatrix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ Status FastTransposeSMatrix(TSMatrix M, TSMatrix* T) {
379379
return ERROR;
380380
}
381381

382-
num = (int*) malloc(M.nu * sizeof(int));
383-
copt = (int*) malloc(M.nu * sizeof(int));
382+
num = (int*) malloc((M.nu + 1) * sizeof(int));
383+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
384384

385385
// 初始化数组num
386386
for(col = 1; col <= M.nu; ++col) {

VisualC++/CourseBook/0503_RLSMatrix/RLSMatrix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ Status FastTransposeSMatrix(RLSMatrix M, RLSMatrix* T) {
420420
return ERROR;
421421
}
422422

423-
num = (int*) malloc(M.nu * sizeof(int));
424-
copt = (int*) malloc(M.nu * sizeof(int));
423+
num = (int*) malloc((M.nu + 1) * sizeof(int));
424+
copt = (int*) malloc((M.nu + 1) * sizeof(int));
425425

426426
// 初始化数组num
427427
for(col = 1; col <= M.nu; ++col) {
0 Bytes
Binary file not shown.
-1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)