Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch sprintf to snprintf #3363

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion faiss/impl/io.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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