Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Use static_cast<T*>(NULL) instead of reinterpret_cast<T*>(NULL) #111

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 cpp/src/sample/subtly/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool SerializeFont(const char* font_path, FontFactory* factory, Font* font) {
#else
output_file = fopen(font_path, "wb");
#endif
if (output_file == reinterpret_cast<FILE*>(NULL))
if (output_file == static_cast<FILE*>(NULL))
return false;
for (size_t i = 0; i < output_stream.Size(); ++i) {
fwrite(&(output_stream.Get()[i]), 1, 1, output_file);
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/sfntly/table/core/cmap_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ CMapTable::CMapFormat0::Builder::Builder(
}

CMapTable::CMapFormat0::Builder::Builder(const CMapId& cmap_id)
: CMap::Builder(reinterpret_cast<ReadableFontData*>(NULL),
: CMap::Builder(static_cast<ReadableFontData*>(NULL),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider switching to nullptr while you are at it?

CMapFormat::kFormat0,
cmap_id) {
}
Expand Down Expand Up @@ -563,7 +563,7 @@ CMapTable::CMapFormat2::Builder::Builder(WritableFontData* data,
: CMapTable::CMap::Builder(data ? down_cast<WritableFontData*>(
data->Slice(offset, data->ReadUShort(
offset + Offset::kFormat0Length)))
: reinterpret_cast<WritableFontData*>(NULL),
: static_cast<WritableFontData*>(NULL),
CMapFormat::kFormat2, cmap_id) {
// TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix.
}
Expand All @@ -574,7 +574,7 @@ CMapTable::CMapFormat2::Builder::Builder(ReadableFontData* data,
: CMapTable::CMap::Builder(data ? down_cast<ReadableFontData*>(
data->Slice(offset, data->ReadUShort(
offset + Offset::kFormat0Length)))
: reinterpret_cast<ReadableFontData*>(NULL),
: static_cast<ReadableFontData*>(NULL),
CMapFormat::kFormat2, cmap_id) {
// TODO(arthurhsu): FIXIT: heavy lifting and leak, need fix.
}
Expand Down Expand Up @@ -958,15 +958,15 @@ CMapTable::CMapFormat4::Builder::Builder(WritableFontData* data, int32_t offset,
CMapTable::CMapFormat4::Builder::Builder(SegmentList* segments,
std::vector<int32_t>* glyph_id_array,
const CMapId& cmap_id)
: CMap::Builder(reinterpret_cast<ReadableFontData*>(NULL),
: CMap::Builder(static_cast<ReadableFontData*>(NULL),
CMapFormat::kFormat4, cmap_id),
segments_(segments->begin(), segments->end()),
glyph_id_array_(glyph_id_array->begin(), glyph_id_array->end()) {
set_model_changed();
}

CMapTable::CMapFormat4::Builder::Builder(const CMapId& cmap_id)
: CMap::Builder(reinterpret_cast<ReadableFontData*>(NULL),
: CMap::Builder(static_cast<ReadableFontData*>(NULL),
CMapFormat::kFormat4, cmap_id) {
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/src/test/autogenerated/cmap_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ void CMapBasicTests::SetUp() {
LoadFont(font_name.c_str(), font_factory, &font_array);
ASSERT_FALSE(font_array.empty());
Ptr<Font> font = font_array.at(0);
ASSERT_NE(font, reinterpret_cast<Font*>(NULL));
ASSERT_NE(font, static_cast<Font*>(NULL));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all the ASSERT/EXPECT EQ/NE checks can just take a nullptr, with no casting.

cmap_table_ = down_cast<CMapTable*>(font->GetTable(Tag::cmap));
if (!cmap_table_)
fprintf(stderr, "No CMap: %s\n", font_name.c_str());
ASSERT_NE(cmap_table_, reinterpret_cast<CMapTable*>(NULL));
ASSERT_NE(cmap_table_, static_cast<CMapTable*>(NULL));

// Loading the XML file
document_ = TiXmlDocument((font_name + ".xml").c_str());
Expand All @@ -85,7 +85,7 @@ TEST_P(CMapBasicTests, BasicTest) {
TiXmlNodeVector* cmaps = GetNodesWithName(cmap_table->at(0), "cmap");
const TiXmlAttribute* num_cmaps_attr = GetAttribute(cmap_table->at(0),
"num_cmaps");
ASSERT_NE(num_cmaps_attr, reinterpret_cast<TiXmlAttribute*>(NULL));
ASSERT_NE(num_cmaps_attr, static_cast<TiXmlAttribute*>(NULL));
// But there may be more than one CMap in this table
ASSERT_LE(cmaps->size(), (size_t)num_cmaps_attr->IntValue());
for (TiXmlNodeVector::iterator it = cmaps->begin();
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/test/cmap_editing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST(CMapEditingTest, RemoveAllButOneCMap) {
FontBuilderPtr font_builder = builders[0];
Ptr<CMapTable::Builder> cmap_table_builder =
(CMapTable::Builder*)font_builder->GetTableBuilder(Tag::cmap);
ASSERT_NE(cmap_table_builder, reinterpret_cast<CMapTable::Builder*>(NULL));
ASSERT_NE(cmap_table_builder, static_cast<CMapTable::Builder*>(NULL));
CMapTable::CMapBuilderMap*
cmap_builders = cmap_table_builder->GetCMapBuilders();
ASSERT_FALSE(cmap_builders->empty());
Expand Down Expand Up @@ -95,7 +95,7 @@ TEST(CMapEditingTest, CopyAllCMapsToNewFont) {
ASSERT_EQ(cmap_table->NumCMaps(), new_cmap_table->NumCMaps());
CMapTable::CMapPtr cmap;
cmap.Attach(cmap_table->GetCMap(CMapTable::WINDOWS_BMP));
ASSERT_NE(cmap, reinterpret_cast<CMapTable::CMap*>(NULL));
ASSERT_NE(cmap, static_cast<CMapTable::CMap*>(NULL));
ASSERT_EQ(CMapTable::WINDOWS_BMP, cmap->cmap_id());
}
}
2 changes: 1 addition & 1 deletion cpp/src/test/cmap_iterator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ TEST_P(CMapIteratorTests, IteratorTest) {
CMapTable::CMap::CharacterIterator* character_iterator = NULL;
character_iterator = cmap_->Iterator();
EXPECT_NE(character_iterator,
reinterpret_cast<CMapTable::CMap::CharacterIterator*>(NULL));
static_cast<CMapTable::CMap::CharacterIterator*>(NULL));
CompareCMapIterAndBitSet(character_iterator, bit_set);
delete character_iterator;
delete bit_set;
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/test/cmap_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ ::std::ostream& operator<<(::std::ostream& os, const CMapTestCase *test_case) {
}

void CMapTests::CommonSetUp(FontArray* font_array) {
ASSERT_NE(font_array, reinterpret_cast<FontArray*>(NULL));
ASSERT_NE(font_array, static_cast<FontArray*>(NULL));
ASSERT_FALSE(font_array->empty());
Ptr<Font> font;
font = font_array->at(0);
ASSERT_NE(font, reinterpret_cast<Font*>(NULL));
ASSERT_NE(font, static_cast<Font*>(NULL));
Ptr<CMapTable> cmap_table =
down_cast<CMapTable*>(font->GetTable(Tag::cmap));
cmap1_.Attach(cmap_table->GetCMap(GetParam().first_platform_id(),
GetParam().first_encoding_id()));
ASSERT_NE((cmap1_), reinterpret_cast<CMapTable::CMap*>(NULL));
ASSERT_NE((cmap1_), static_cast<CMapTable::CMap*>(NULL));
cmap2_.Attach(cmap_table->GetCMap(GetParam().second_platform_id(),
GetParam().second_encoding_id()));
ASSERT_NE((cmap2_), reinterpret_cast<CMapTable::CMap*>(NULL));
ASSERT_NE((cmap2_), static_cast<CMapTable::CMap*>(NULL));
encoder1_ = TestUtils::GetEncoder(GetParam().first_charset_name());
encoder2_ = TestUtils::GetEncoder(GetParam().second_charset_name());
successful_setup_ = true;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/test/test_font_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void LoadFile(const char* input_file_path, ByteVector* input_buffer) {
#else
input_file = fopen(input_file_path, "rb");
#endif
EXPECT_NE(input_file, reinterpret_cast<FILE*>(NULL));
EXPECT_NE(input_file, static_cast<FILE*>(NULL));
fseek(input_file, 0, SEEK_END);
size_t file_size = ftell(input_file);
fseek(input_file, 0, SEEK_SET);
Expand All @@ -90,7 +90,7 @@ void SerializeToFile(MemoryOutputStream* output_stream, const char* file_path) {
#else
output_file = fopen(file_path, "wb");
#endif
EXPECT_NE(output_file, reinterpret_cast<FILE*>(NULL));
EXPECT_NE(output_file, static_cast<FILE*>(NULL));
fwrite(output_stream->Get(), 1, output_stream->Size(), output_file);
fflush(output_file);
fclose(output_file);
Expand Down