Skip to content

Commit

Permalink
emess(): avoid potential unsafe uses
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 10, 2024
1 parent 30ed828 commit ef2bb0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/apps/cs2cs.cpp
Expand Up @@ -899,7 +899,7 @@ int main(int argc, char **argv) {
sourceEpochDbl = c_locale_stod(sourceEpoch);
} catch (const std::exception &e) {
sourceEpochDbl = 0;
emess(3, e.what());
emess(3, "%s", e.what());
}
srcMetadata =
proj_coordinate_metadata_create(nullptr, src, sourceEpochDbl);
Expand All @@ -917,7 +917,7 @@ int main(int argc, char **argv) {
targetEpochDbl = c_locale_stod(targetEpoch);
} catch (const std::exception &e) {
targetEpochDbl = 0;
emess(3, e.what());
emess(3, "%s", e.what());
}
dstMetadata =
proj_coordinate_metadata_create(nullptr, dst, targetEpochDbl);
Expand Down
9 changes: 8 additions & 1 deletion src/apps/emess.h
Expand Up @@ -19,6 +19,13 @@ extern struct EMESS emess_dat;

#endif /* use type */

void emess(int, const char *, ...);
#if defined(__GNUC__)
#define EMESS_PRINT_FUNC_FORMAT(format_idx, arg_idx) \
__attribute__((__format__(__printf__, format_idx, arg_idx)))
#else
#define EMESS_PRINT_FUNC_FORMAT(format_idx, arg_idx)
#endif

void emess(int, const char *, ...) EMESS_PRINT_FUNC_FORMAT(2, 3);

#endif /* end EMESS_H */
2 changes: 1 addition & 1 deletion src/apps/proj.cpp
Expand Up @@ -279,7 +279,7 @@ static void vprocess(FILE *fid) {
}

if (proj_context_errno(nullptr)) {
emess(-1, proj_errno_string(proj_context_errno(nullptr)));
emess(-1, "%s", proj_errno_string(proj_context_errno(nullptr)));
continue;
}

Expand Down

0 comments on commit ef2bb0e

Please sign in to comment.