mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
be7a6b5cb3
Summary: While hacking on some code, I ran into a situation where some zero-initialized stat structs weren't actually being zeroed. This was either a compiler bug or a situation where the build system was not correctly rebuilding everything after my changes, and I did not have enough disassembly available to investigate. Either way, since this code assumes zero bits in some nonobvious ways, explicitly assert they are. Reviewed By: xavierd Differential Revision: D23644819 fbshipit-source-id: eb6bff9ff997379113db1e1bf9d6a0a538f10f0b
31 lines
720 B
C++
31 lines
720 B
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/utils/Memory.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
namespace facebook::eden {
|
|
|
|
void assertZeroBits(const void* memory, size_t size) {
|
|
if (0 == size) {
|
|
return;
|
|
}
|
|
auto* p = static_cast<const unsigned char*>(memory);
|
|
if (p[0] || memcmp(p, p + 1, size - 1)) {
|
|
fprintf(stderr, "unexpected nonzero bits: ");
|
|
for (size_t i = 0; i < size; ++i) {
|
|
fprintf(stderr, "%01x%01x", p[i] & 15, p[i] >> 4);
|
|
}
|
|
fprintf(stderr, "\n");
|
|
fflush(stderr);
|
|
abort();
|
|
}
|
|
}
|
|
} // namespace facebook::eden
|