Skip to content

Commit

Permalink
ParU: fix printf formating, found by CodeQL
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Oct 29, 2023
1 parent 1f17b45 commit e935e13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
20 changes: 11 additions & 9 deletions ParU/Source/paru_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* @author Aznaveh
*/
#define LD "%" PRId64

#include "paru_internal.hpp"
void paru_print_element(int64_t e, paru_work *Work, ParU_Numeric *Num)
{
Expand All @@ -23,14 +25,14 @@ void paru_print_element(int64_t e, paru_work *Work, ParU_Numeric *Num)

if (e > morign + nf + 1)
{
printf("%% paru_element %ld is out of range; just %ld elements \n", e,
printf("%% paru_element " LD " is out of range; just " LD " elements \n", e,
morign + nf + 1);
return;
}

if (curEl == NULL)
{
printf("%% paru_element %ld is empty\n", e);
printf("%% paru_element " LD " is empty\n", e);
return;
}

Expand All @@ -47,19 +49,19 @@ void paru_print_element(int64_t e, paru_work *Work, ParU_Numeric *Num)
double *el_colrowNum = numeric_pointer(curEl);

printf("\n");
printf("%% paru_element %ld is %ld x %ld:\n", e, m, n);
printf("%% paru_element " LD " is " LD " x " LD ":\n", e, m, n);

printf("\t");
// for (int j = 0; j < n; j++)
// printf("%% %ld\t", rel_col[j] );
// printf("%% " LD "\t", rel_col[j] );
// printf("\n\t");
for (int j = 0; j < n; j++) printf("%% %ld\t", el_colIndex[j]);
for (int j = 0; j < n; j++) printf("%% " LD "\t", el_colIndex[j]);

printf("\n");
for (int i = 0; i < m; i++)
{
// printf("%% %ld\t %ld\t",rel_row[i], el_rowIndex [i] );
printf("%% %ld\t", el_rowIndex[i]);
// printf("%% " LD "\t " LD "\t",rel_row[i], el_rowIndex [i] );
printf("%% " LD "\t", el_rowIndex[i]);
for (int j = 0; j < n; j++)
{
double value = el_colrowNum[j * m + i];
Expand All @@ -84,11 +86,11 @@ void paru_print_paru_tupleList(paru_tupleList *listSet, int64_t index)
int64_t numTuple = cur.numTuple;
paru_tuple *l = cur.list;

printf("%% There are %ld tuples in this list:\n %%", numTuple);
printf("%% There are " LD " tuples in this list:\n %%", numTuple);
for (int64_t i = 0; i < numTuple; i++)
{
paru_tuple curTpl = l[i];
printf(" (%ld,%ld)", curTpl.e, curTpl.f);
printf(" (" LD "," LD ")", curTpl.e, curTpl.f);
}
printf("\n");
}
19 changes: 11 additions & 8 deletions ParU/Source/paru_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* it must be called after the results are computed
* @author Aznaveh
*/

#define LD "%" PRId64

#include "paru_internal.hpp"
void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
{
Expand Down Expand Up @@ -57,7 +60,7 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
for (int64_t col = 0; col < n; col++)
{ // for each column of A(:,Qfill)
int64_t j = Qfill ? Qfill[col] : col; // col of S is column j of A
fprintf(colfptr, "%ld\n", j);
fprintf(colfptr, LD "\n", j);
}

fclose(colfptr);
Expand Down Expand Up @@ -111,7 +114,7 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
int64_t ip = 0; // number of rows seen so far
for (int64_t k = 0; k < n1; k++)
// first singletons
fprintf(rowfptr, "%ld\n", Pinit[k]);
fprintf(rowfptr, LD "\n", Pinit[k]);

for (int64_t f = 0; f < nf; f++)
{ // rows for each front
Expand All @@ -124,7 +127,7 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
{
oldRofS[ip++] = frowList[k]; // computing permutation for S
// P[k] = i
fprintf(rowfptr, "%ld\n", Pinit[frowList[k]]);
fprintf(rowfptr, LD "\n", Pinit[frowList[k]]);
}
}
fclose(rowfptr);
Expand Down Expand Up @@ -237,7 +240,7 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)

fprintf(LUfptr, "%%%%MatrixMarket matrix coordinate real general\n");
fprintf(LUfptr, "%%-----------produced by ParU ---------------\n");
fprintf(LUfptr, "%ld %ld %ld\n", m, n, nnz);
fprintf(LUfptr, LD " " LD " " LD "\n", m, n, nnz);

// writing the singletons
// (I haven't add that part yet)
Expand All @@ -260,14 +263,14 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
for (int64_t i = 0; i < rowCount; i++)
{
if (pivotalFront[(j - col1) * rowCount + i] != 0.0)
fprintf(LUfptr, "%ld %ld %.17g\n",
fprintf(LUfptr, LD " " LD " %.17g\n",
newRofS[frowList[i]] + n1 + 1, j + n1 + 1,
pivotalFront[(j - col1) * rowCount + i]);
}

#ifndef NDEBUG // Printing the pivotal front
int64_t p = 1;
PRLEVEL(p, ("\n%%Inside paru_write Luf{%ld}= [", f + 1));
PRLEVEL(p, ("\n%%Inside paru_write Luf{" LD "}= [", f + 1));
for (int64_t r = 0; r < rowCount; r++)
{
PRLEVEL(p, (" "));
Expand All @@ -285,14 +288,14 @@ void paru_write(int scale, char *id, paru_work *Work, ParU_Numeric *Num)
for (int64_t i = 0; i < fp; i++)
{
if (uPart[fp * j + i] != 0.0)
fprintf(LUfptr, "%ld %ld %.17g\n",
fprintf(LUfptr, LD " " LD " %.17g\n",
newRofS[frowList[i]] + n1 + 1, fcolList[j] + n1 + 1,
uPart[fp * j + i]);
}
#ifndef NDEBUG // Printing the U part
p = 1;
PRLEVEL(p, ("\n"));
PRLEVEL(p, ("%% fp = %ld, colCount = %ld\n", fp, colCount));
PRLEVEL(p, ("%% fp = " LD ", colCount = " LD "\n", fp, colCount));
if (colCount != 0)
{
for (int64_t i = 0; i < fp; i++)
Expand Down

0 comments on commit e935e13

Please sign in to comment.