Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18703
`zeroPtr` is sometimes a `std::string` tensor, so `memset` to 0 is undefined behavior.
This might be accidentally safe with `std::string` implementation that use SSO (Small String Optimization), but will crash otherwise.
Reviewed By: zheng-xq
Differential Revision:
D14714458
fbshipit-source-id:
012a18464e6514d38ff791509b88ddc3fc55b2b1
Tensor zero{CPU};
zero.Resize(block_size);
auto zeroPtr = static_cast<char*>(zero.raw_mutable_data(features.dtype()));
- memset(zeroPtr, 0, zero.nbytes());
+ // TODO Handle other composite types, such as vector<...>
+ if (!features.dtype().Match<std::string>()) {
+ memset(zeroPtr, 0, zero.nbytes());
+ }
int start_dest = 0;
int start_src = 0;
for (int i = 0; i < lengths.numel(); ++i) {