Skip to content

Commit 7d049f2

Browse files
authored
Cleanup warnings by scanBuild (#444)
* v0 * v1 * v2 * fix buffer * Revert buffer changes * Fix * Fix * Revert otel_process_ctx.cpp * Fix uninitialized varible * scanBuild to include subdirectories * Changes based on comments
1 parent 5ed7a66 commit 7d049f2

28 files changed

Lines changed: 67 additions & 71 deletions

ddprof-lib/src/main/cpp/arguments.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class Arguments {
202202
_wall(-1),
203203
_wall_collapsing(false),
204204
_wall_threads_per_tick(DEFAULT_WALL_THREADS_PER_TICK),
205+
_wallclock_sampler(ASGCT),
205206
_memory(-1),
206207
_record_allocations(false),
207208
_record_liveness(false),
@@ -220,10 +221,10 @@ class Arguments {
220221
_clock(CLK_DEFAULT),
221222
_jfr_options(0),
222223
_context_attributes({}),
223-
_wallclock_sampler(ASGCT),
224224
_lightweight(false),
225225
_enable_method_cleanup(true),
226-
_remote_symbolication(false) {}
226+
_remote_symbolication(false) { }
227+
227228

228229
~Arguments();
229230

ddprof-lib/src/main/cpp/buffers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class RecordingBuffer : public Buffer {
229229
public:
230230
RecordingBuffer() : Buffer() {
231231
new (_data + sizeof(_data)) char[sizeof(_buf)];
232-
memset(_buf, 0, _limit);
232+
memset(_buf, 0, _limit);
233233
}
234234

235235
int limit() const override { return _limit; }

ddprof-lib/src/main/cpp/callTraceHashTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void init_overflow_trace() {
8585
CallTraceHashTable::_overflow_trace.frames[0] = {BCI_ERROR, LP64_ONLY(0 COMMA) (jmethodID)"storage_overflow"};
8686
}
8787

88-
CallTraceHashTable::CallTraceHashTable() : _allocator(CALL_TRACE_CHUNK), _instance_id(0), _parent_storage(nullptr) {
88+
CallTraceHashTable::CallTraceHashTable() : _instance_id(0), _parent_storage(nullptr), _allocator(CALL_TRACE_CHUNK) {
8989
// Instance ID will be set externally via setInstanceId()
9090

9191
// Start with initial capacity, allowing expansion as needed

ddprof-lib/src/main/cpp/callTraceStorage.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ class CallTraceStorage {
142142
std::unordered_set<CallTrace*> _traces_buffer; // All traces for JFR processing
143143
std::unordered_set<u64> _preserve_set_buffer; // Preserve set for current cycle
144144

145-
146-
private:
147-
148-
149-
150-
151145
public:
152146
CallTraceStorage();
153147
~CallTraceStorage();

ddprof-lib/src/main/cpp/codeCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void CodeCache::findSymbolsByPrefix(std::vector<const char *> &prefixes,
284284
for (int i = 0; i < _count; i++) {
285285
const char *blob_name = _blobs[i]._name;
286286
if (blob_name != NULL) {
287-
for (int i = 0; i < prefixes.size(); i++) {
287+
for (size_t i = 0; i < prefixes.size(); i++) {
288288
if (strncmp(blob_name, prefixes[i], prefix_lengths[i]) == 0) {
289289
symbols.push_back(_blobs[i]._start);
290290
}

ddprof-lib/src/main/cpp/context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Context& Contexts::initializeContextTls() {
3838
return ctx;
3939
}
4040

41+
static Context DD_EMPTY_CONTEXT = {};
42+
4143
Context& Contexts::get() {
4244
ProfiledThread* thrd = ProfiledThread::currentSignalSafe();
4345
if (thrd == nullptr || !thrd->isContextTlsInitialized()) {

ddprof-lib/src/main/cpp/context.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class alignas(DEFAULT_CACHE_LINE_SIZE) Context {
3939
Tag get_tag(int i) { return tags[i]; }
4040
};
4141

42-
static Context DD_EMPTY_CONTEXT = {};
43-
4442
class Contexts {
4543

4644
public:

ddprof-lib/src/main/cpp/dwarf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const int INITIAL_PC_OFFSET = DW_LINK_REGISTER;
7474

7575
struct FrameDesc {
7676
u32 loc;
77-
int cfa;
77+
u32 cfa;
7878
int fp_off;
7979
int pc_off;
8080

ddprof-lib/src/main/cpp/flightRecorder.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ void Recording::writeMetadata(Buffer *buf) {
808808

809809
std::vector<std::string> &strings = JfrMetadata::strings();
810810
buf->putVar64(strings.size());
811-
for (int i = 0; i < strings.size(); i++) {
811+
for (size_t i = 0; i < strings.size(); i++) {
812812
const char *string = strings[i].c_str();
813813
int length = strlen(string);
814814
flushIfNeeded(buf, RECORDING_BUFFER_LIMIT - length);
@@ -842,14 +842,14 @@ void Recording::writeElement(Buffer *buf, const Element *e) {
842842
buf->putVar64(e->_name);
843843

844844
buf->putVar64(e->_attributes.size());
845-
for (int i = 0; i < e->_attributes.size(); i++) {
845+
for (size_t i = 0; i < e->_attributes.size(); i++) {
846846
flushIfNeeded(buf);
847847
buf->putVar64(e->_attributes[i]._key);
848848
buf->putVar64(e->_attributes[i]._value);
849849
}
850850

851851
buf->putVar64(e->_children.size());
852-
for (int i = 0; i < e->_children.size(); i++) {
852+
for (size_t i = 0; i < e->_children.size(); i++) {
853853
flushIfNeeded(buf);
854854
writeElement(buf, e->_children[i]);
855855
}
@@ -1426,7 +1426,7 @@ void Recording::writeCounters(Buffer *buf) {
14261426
long long *counters = Counters::getCounters();
14271427
if (counters) {
14281428
std::vector<const char *> names = Counters::describeCounters();
1429-
for (int i = 0; i < names.size(); i++) {
1429+
for (size_t i = 0; i < names.size(); i++) {
14301430
int start = buf->skip(1);
14311431
buf->putVar64(T_DATADOG_COUNTER);
14321432
buf->putVar64(_start_ticks);
@@ -1683,10 +1683,11 @@ void FlightRecorder::stop() {
16831683
}
16841684

16851685
Error FlightRecorder::dump(const char *filename, const int length) {
1686+
assert(length >= 0);
16861687
ExclusiveLockGuard locker(&_rec_lock);
16871688
Recording* rec = _rec;
16881689
if (rec != nullptr) {
1689-
if (_filename.length() != length ||
1690+
if (_filename.length() != static_cast<size_t>(length) ||
16901691
strncmp(filename, _filename.c_str(), length) != 0) {
16911692
// if the filename to dump the recording to is specified move the current
16921693
// working file there

ddprof-lib/src/main/cpp/hotspot/vmStructs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ HeapUsage HeapUsage::get(bool allow_jmx) {
11031103
usage._maxSize = summary.maxSize();
11041104
}
11051105
}
1106-
if (usage._maxSize == -1 && _memory_usage_func != NULL && allow_jmx && isJMXSupported()) {
1106+
if (usage._maxSize == size_t(-1) && _memory_usage_func != NULL && allow_jmx && isJMXSupported()) {
11071107
// this path is for non-hotspot JVMs
11081108
// we need to patch the native method binding for JMX GetMemoryUsage to
11091109
// capture the native method pointer first also, it requires JMX and

0 commit comments

Comments
 (0)