Skip to content

Commit efd27a5

Browse files
author
Dave Allison
committed
Fix pedentic warnings
1 parent 6143890 commit efd27a5

11 files changed

Lines changed: 391 additions & 130 deletions

File tree

MODULE.bazel.lock

Lines changed: 232 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toolbelt/color.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ struct Color {
4848
FixedColor fixed = FixedColor::kNotSet;
4949

5050
// Your terminal might not support this.
51-
int eight; // 8-bit color for k8bit.
51+
int eight = 0; // 8-bit color for k8bit.
5252

5353
// If fixed is kNotSet, these are RGB values for the color.
5454
// Your terminal may not support this.
55-
int r;
56-
int g;
57-
int b;
55+
int r = 0;
56+
int g = 0;
57+
int b = 0;
5858
};
5959

6060
// Make a 3-bit fixed color.

toolbelt/fd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class FileDescriptor {
9898
// Construct and return a struct pollfd suitable for use in ::poll.
9999
struct pollfd GetPollFd() {
100100
if (data_ == nullptr) {
101-
return {.fd = -1, .events = POLLIN};
101+
return {.fd = -1, .events = POLLIN, .revents = 0};
102102
}
103-
return {.fd = data_->fd, .events = POLLIN};
103+
return {.fd = data_->fd, .events = POLLIN, .revents = 0};
104104
}
105105

106106
bool operator==(const FileDescriptor &fd) const {

toolbelt/payload_buffer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ BitMapRun *PayloadBuffer::AllocateBitMapRun(PayloadBuffer **self, uint32_t size,
732732
return run;
733733
}
734734

735-
void *BitMapRun::Allocate(PayloadBuffer **pb, int index, uint32_t n, int size,
735+
void *BitMapRun::Allocate(PayloadBuffer **pb, int index, uint32_t, int size,
736736
int num, bool clear) {
737737
// Lazy init of vector.
738738
if ((*pb)->bitmaps[index] == 0) {

toolbelt/payload_buffer.h

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22

33
#include "absl/types/span.h"
4+
#include "toolbelt/hexdump.h"
45
#include <functional>
56
#include <iostream>
67
#include <stdint.h>
78
#include <stdlib.h>
89
#include <string.h>
910
#include <string>
1011
#include <string_view>
11-
#include "toolbelt/hexdump.h"
1212

1313
namespace toolbelt {
1414

@@ -228,7 +228,7 @@ struct PayloadBuffer {
228228
return (p[word] & (1 << bit)) != 0;
229229
}
230230

231-
static uint32_t DecodeSize(BufferOffset* addr) {
231+
static uint32_t DecodeSize(BufferOffset *addr) {
232232
// Length is 64 bits long but we only need the bottom 32 bits of it.
233233
uint32_t *p = reinterpret_cast<uint32_t *>(addr) - 2;
234234
if ((*p & (1U << 31)) == 0) {
@@ -314,12 +314,11 @@ struct PayloadBuffer {
314314
FreeBlockHeader *FreeList() { return ToAddress<FreeBlockHeader>(free_list); }
315315

316316
// Allocate some memory in the buffer. The buffer might move.
317-
static void *Allocate(PayloadBuffer **buffer, uint32_t n,
318-
bool clear = true, bool enable_small_block = true);
317+
static void *Allocate(PayloadBuffer **buffer, uint32_t n, bool clear = true,
318+
bool enable_small_block = true);
319319
void Free(void *p);
320320
static void *Realloc(PayloadBuffer **buffer, void *p, uint32_t n,
321-
bool clear = true,
322-
bool enable_small_block = true);
321+
bool clear = true, bool enable_small_block = true);
323322
static BufferOffset AllocateBitMapRunVector(PayloadBuffer **self);
324323
static void *AllocateSmallBlock(PayloadBuffer **pb, uint32_t size, int index,
325324
bool clear = true);
@@ -331,8 +330,7 @@ struct PayloadBuffer {
331330
// individually. The addresses of the allocated items are returned in a
332331
// vector.
333332
static std::vector<void *> AllocateMany(PayloadBuffer **buffer, uint32_t size,
334-
uint32_t n,
335-
bool clear = true);
333+
uint32_t n, bool clear = true);
336334

337335
bool IsValidMagic() const {
338336
uint32_t m = magic & kBitMapMask;
@@ -353,12 +351,12 @@ struct PayloadBuffer {
353351
// Given the address of a block, return the size of the block. This is
354352
// in the previous 8 bytes but might be encoded if the block is a small
355353
// block.
356-
static uint32_t DecodedSize(BufferOffset* addr) {
357-
BufferOffset* p = addr - 2;
358-
if (*p & (1U << 31)) {
359-
return *p & kBitmapRunSizeMask;
360-
}
361-
return *p;
354+
static uint32_t DecodedSize(BufferOffset *addr) {
355+
BufferOffset *p = addr - 2;
356+
if (*p & (1U << 31)) {
357+
return *p & kBitmapRunSizeMask;
358+
}
359+
return *p;
362360
}
363361

364362
template <typename T = void>
@@ -483,21 +481,28 @@ inline void PayloadBuffer::VectorPush(PayloadBuffer **self, VectorHeader *hdr,
483481
// BufferOffset data; - BufferOffset to vector contents
484482
// The vector contents is allocated in the buffer. It is preceded
485483
// by the block size (in bytes).
484+
BufferOffset hdr_offset = (*self)->ToOffset(hdr);
485+
486486
uint32_t total_size = hdr->num_elements * sizeof(T);
487487
if (hdr->data == 0) {
488488
// The vector is empty, allocate it with a default size of 2.
489489
void *vecp = Allocate(self, 2 * sizeof(T), true, enable_small_block);
490490
hdr->data = (*self)->ToOffset(vecp);
491+
VectorHeader *new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
492+
new_hdr->data = (*self)->ToOffset(vecp);
493+
hdr = new_hdr;
491494
} else {
492495
// Vector has some values in it. Retrieve the total size from
493496
// the allocated block header (before the start of the memory)
494497
uint32_t *block = (*self)->ToAddress<uint32_t>(hdr->data);
495498
uint32_t current_size = DecodeSize(block);
496499
if (current_size == total_size) {
497500
// Need to double the size of the memory.
498-
void *vecp = Realloc(self, block, 2 * hdr->num_elements * sizeof(T),
499-
true, enable_small_block);
500-
hdr->data = (*self)->ToOffset(vecp);
501+
void *vecp = Realloc(self, block, 2 * hdr->num_elements * sizeof(T), true,
502+
enable_small_block);
503+
VectorHeader *new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
504+
new_hdr->data = (*self)->ToOffset(vecp);
505+
hdr = new_hdr;
501506
}
502507
}
503508
// Get address of next location in vector.
@@ -512,9 +517,12 @@ template <typename T>
512517
inline void PayloadBuffer::VectorReserve(PayloadBuffer **self,
513518
VectorHeader *hdr, size_t n,
514519
bool enable_small_block) {
520+
BufferOffset hdr_offset = (*self)->ToOffset(hdr);
515521
if (hdr->data == 0) {
516522
void *vecp = Allocate(self, n * sizeof(T), false, enable_small_block);
517-
hdr->data = (*self)->ToOffset(vecp);
523+
VectorHeader* new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
524+
new_hdr->data = (*self)->ToOffset(vecp);
525+
hdr = new_hdr;
518526
} else {
519527
// Vector has some values in it. Retrieve the total size from
520528
// the allocated block header (before the start of the memory)
@@ -524,17 +532,22 @@ inline void PayloadBuffer::VectorReserve(PayloadBuffer **self,
524532
// Need to expand the memory to the size given.
525533
void *vecp =
526534
Realloc(self, block, n * sizeof(T), false, enable_small_block);
527-
hdr->data = (*self)->ToOffset(vecp);
535+
VectorHeader* new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
536+
new_hdr->data = (*self)->ToOffset(vecp);
537+
hdr = new_hdr;
528538
}
529539
}
530540
}
531541

532542
template <typename T>
533543
inline void PayloadBuffer::VectorResize(PayloadBuffer **self, VectorHeader *hdr,
534544
size_t n) {
545+
BufferOffset hdr_offset = (*self)->ToOffset(hdr);
535546
if (hdr->data == 0) {
536547
void *vecp = Allocate(self, n * sizeof(T));
537-
hdr->data = (*self)->ToOffset(vecp);
548+
VectorHeader* new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
549+
new_hdr->data = (*self)->ToOffset(vecp);
550+
hdr = new_hdr;
538551
} else {
539552
// Vector has some values in it. Retrieve the total size from
540553
// the allocated block header (before the start of the memory)
@@ -543,7 +556,9 @@ inline void PayloadBuffer::VectorResize(PayloadBuffer **self, VectorHeader *hdr,
543556
if (current_size < n * sizeof(T)) {
544557
// Need to expand the memory to the size given.
545558
void *vecp = Realloc(self, block, n * sizeof(T), 8);
546-
hdr->data = (*self)->ToOffset(vecp);
559+
VectorHeader* new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
560+
new_hdr->data = (*self)->ToOffset(vecp);
561+
hdr = new_hdr;
547562
}
548563
}
549564
hdr->num_elements = n;

toolbelt/payload_buffer_test.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ TEST(BufferTest, TypicalPerformance) {
338338
for (int j = 0; j < 1000; j++) {
339339
int prev_size = int(large_blocks.size());
340340
for (int i = 0; i < kNumBlocks; i++) {
341-
void *addr = PayloadBuffer::Allocate(&pb, 10, false, /*enable_small_block=*/false);
341+
void *addr = PayloadBuffer::Allocate(&pb, 10, false,
342+
/*enable_small_block=*/false);
342343
large_blocks.push_back(addr);
343344
}
344345
// Free some of the blocks.
@@ -367,8 +368,7 @@ TEST(BufferTest, Many) {
367368
char *buffer = (char *)malloc(kSize);
368369
PayloadBuffer *pb = new (buffer) PayloadBuffer(kSize);
369370

370-
std::vector<void *> addrs =
371-
PayloadBuffer::AllocateMany(&pb, 100, 10, true);
371+
std::vector<void *> addrs = PayloadBuffer::AllocateMany(&pb, 100, 10, true);
372372
ASSERT_EQ(10, addrs.size());
373373
// Print the addresses.
374374
for (auto addr : addrs) {
@@ -497,10 +497,22 @@ TEST(BufferTest, VectorExpandMore) {
497497
TEST(BufferTest, Resizeable) {
498498
char *buffer = (char *)malloc(512);
499499
bool resized = false;
500-
PayloadBuffer *pb = new (buffer)
501-
PayloadBuffer(256, [&resized](PayloadBuffer **p, size_t old_size, size_t new_size) {
500+
PayloadBuffer *pb = new (buffer) PayloadBuffer(
501+
256, [&resized](PayloadBuffer **p, size_t, size_t new_size) {
502502
std::cout << "resize for " << new_size << std::endl;
503+
#if defined(__clang__)
504+
#pragma clang diagnostic push
505+
#pragma clang diagnostic ignored "-Wclass-memaccess"
506+
#elif defined(__GNUC__)
507+
#pragma GCC diagnostic push
508+
#pragma GCC diagnostic ignored "-Wclass-memaccess"
509+
#endif
503510
*p = reinterpret_cast<PayloadBuffer *>(realloc(*p, new_size));
511+
#if defined(__clang__)
512+
#pragma clang diagnostic pop
513+
#elif defined(__GNUC__)
514+
#pragma GCC diagnostic pop
515+
#endif
504516
resized = true;
505517
});
506518
pb->Dump(std::cout);

toolbelt/pipe.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ template <typename T> class SharedPtrPipe : public Pipe {
150150
SharedPtrPipe(int r, int w) : Pipe(r, w) {}
151151

152152
// You can't use raw buffers with shared ptr pipes.
153-
absl::StatusOr<ssize_t> Read(char *buffer, size_t length,
154-
const co::Coroutine *c = nullptr) override {
153+
absl::StatusOr<ssize_t> Read(char *, size_t ,
154+
const co::Coroutine * = nullptr) override {
155155
return absl::InternalError("Not supported on SharedPtrPipe");
156156
}
157-
absl::StatusOr<ssize_t> Write(const char *buffer, size_t length,
157+
absl::StatusOr<ssize_t> Write(const char *, size_t ,
158158
const co::Coroutine *c = nullptr) override {
159159
return absl::InternalError("Not supported on SharedPtrPipe");
160160
}

0 commit comments

Comments
 (0)