Skip to content

Commit

Permalink
Switch sprintf to snprintf (#3363)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #3363

'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead

{F1484071654}

Reviewed By: kuarora

Differential Revision: D56009251

fbshipit-source-id: ec222cf589ff98b016979058d59fc20cccec8f43
  • Loading branch information
junjieqi authored and facebook-github-bot committed Apr 12, 2024
1 parent 40e8643 commit acd06d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion faiss/impl/io.cpp
Expand Up @@ -267,7 +267,7 @@ std::string fourcc_inv_printable(uint32_t x) {
str += c;
} else {
char buf[10];
sprintf(buf, "\\x%02x", c);
snprintf(buf, sizeof(buf), "\\x%02x", c);
str += buf;
}
}
Expand Down
9 changes: 8 additions & 1 deletion faiss/utils/simdlib_neon.h
Expand Up @@ -168,9 +168,16 @@ static inline std::string elements_to_string(const char* fmt, const S& simd) {
simd.store(bytes);
char res[1000], *ptr = res;
for (size_t i = 0; i < N; ++i) {
ptr += sprintf(ptr, fmt, bytes[i]);
int bytesWritten =
snprintf(ptr, sizeof(res) - (ptr - res), fmt, bytes[i]);
if (bytesWritten >= 0) {
ptr += bytesWritten;
} else {
break;
}
}
// strip last ,

ptr[-1] = 0;
return std::string(res);
}
Expand Down

0 comments on commit acd06d6

Please sign in to comment.