Skip to content

Commit

Permalink
Fix compiler warning printing size_t (#10779)
Browse files Browse the repository at this point in the history
- Print size_t with %zu

Co-authored-by: AnHeuermann <38031952+AnHeuermann@users.noreply.github.com>
  • Loading branch information
phannebohm and AnHeuermann committed May 31, 2023
1 parent 4a16421 commit 412f085
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/SimCode/SerializeSparsityPattern.mo
Expand Up @@ -86,7 +86,7 @@ protected
j += (unsigned int) MMC_UNTAGFIXNUM(MMC_STRUCTDATA(colPtrs)[i]);
count = omc_fwrite(&j, sizeof(unsigned int), 1, pFile);
if (count != 1) {
throwStreamPrint(NULL, \"Error while writing sparsePattern->leadindex. Expected %d, got %ld\", 1, count);
throwStreamPrint(NULL, \"Error while writing sparsePattern->leadindex. Expected %d, got %zu\", 1, count);
}
}
Expand All @@ -95,7 +95,7 @@ protected
j = (unsigned int) MMC_UNTAGFIXNUM(MMC_STRUCTDATA(rowInds)[i]);
count = omc_fwrite(&j, sizeof(unsigned int), 1, pFile);
if (count != 1) {
throwStreamPrint(NULL, \"Error while writing sparsePattern->index. Expected %d, got %ld\", 1, count);
throwStreamPrint(NULL, \"Error while writing sparsePattern->index. Expected %d, got %zu\", 1, count);
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ protected
j = (unsigned int) MMC_UNTAGFIXNUM(MMC_STRUCTDATA(columns)[i]);
count = omc_fwrite(&j, sizeof(unsigned int), 1, pFile);
if (count != 1) {
throwStreamPrint(NULL, \"Error while writing sparsePattern->colorCols. Expected %d, got %ld\", 1, count);
throwStreamPrint(NULL, \"Error while writing sparsePattern->colorCols. Expected %d, got %zu\", 1, count);
}
}
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/Template/CodegenC.tpl
Expand Up @@ -5586,13 +5586,13 @@ match sparsepattern
/* read lead index of compressed sparse column */
count = omc_fread(jacobian->sparsePattern->leadindex, sizeof(unsigned int), <%sizeleadindex%>+1, pFile, FALSE);
if (count != <%sizeleadindex%>+1) {
throwStreamPrint(threadData, "Error while reading lead index list of sparsity pattern. Expected %d, got %ld", <%sizeleadindex%>+1, count);
throwStreamPrint(threadData, "Error while reading lead index list of sparsity pattern. Expected %d, got %zu", <%sizeleadindex%>+1, count);
}

/* read sparse index */
count = omc_fread(jacobian->sparsePattern->index, sizeof(unsigned int), <%sp_size_index%>, pFile, FALSE);
if (count != <%sp_size_index%>) {
throwStreamPrint(threadData, "Error while reading row index list of sparsity pattern. Expected %d, got %ld", <%sizeleadindex%>+1, count);
throwStreamPrint(threadData, "Error while reading row index list of sparsity pattern. Expected %d, got %zu", <%sizeleadindex%>+1, count);
}

/* write color array */
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/SimulationRuntime/c/simulation/jacobian_util.c
Expand Up @@ -175,7 +175,7 @@ void readSparsePatternColor(threadData_t* threadData, FILE * pFile, unsigned int
for (i = 0; i < length; i++) {
count = omc_fread(&index, sizeof(unsigned int), 1, pFile, FALSE);
if (count != 1) {
throwStreamPrint(threadData, "Error while reading color %d of sparsity pattern.", color);
throwStreamPrint(threadData, "Error while reading color %u of sparsity pattern.", color);
}
colorCols[index] = color;
}
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/SimulationRuntime/c/util/omc_file.c
Expand Up @@ -145,7 +145,7 @@ size_t omc_fread(void *buffer, size_t size, size_t count, FILE *stream, int allo
if(read_len != count) {
if (feof(stream) && !allow_early_eof) {
fprintf(stderr, "Error reading stream: unexpected end of file.\n");
fprintf(stderr, "Expected to read %ld. Read only %ld\n", count, read_len);
fprintf(stderr, "Expected to read %zu. Read only %zu\n", count, read_len);
}
else if (ferror(stream)) {
fprintf(stderr, "Error: omc_fread() failed to read file.\n");
Expand All @@ -171,7 +171,7 @@ size_t omc_fwrite(void *buffer, size_t size, size_t count, FILE *stream) {
}
if (write_len != count) {
fprintf(stderr, "Error writing stream: unexpected end of file.\n");
fprintf(stderr, "Expected to write %ld. Wrote only %ld\n", count, write_len);
fprintf(stderr, "Expected to write %zu. Wrote only %zu\n", count, write_len);
}

return write_len;
Expand Down

0 comments on commit 412f085

Please sign in to comment.