From 6f72cbffabd9ab0d13f0211105a26dd6b8abe52d Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 5 Nov 2019 11:17:23 +0100 Subject: [PATCH] fix snprintf of uint64 for ARM --- lib/include/srslte/common/bounded_bitset.h | 21 +++++++++++---------- lib/src/common/log_filter.cc | 7 ++++--- lib/src/common/pdu.cc | 3 ++- srsenb/src/stack/mac/ue.cc | 3 ++- srsue/src/phy/sf_worker.cc | 2 +- srsue/src/stack/mac/proc_ra.cc | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/include/srslte/common/bounded_bitset.h b/lib/include/srslte/common/bounded_bitset.h index 407544068..faeec15a5 100644 --- a/lib/include/srslte/common/bounded_bitset.h +++ b/lib/include/srslte/common/bounded_bitset.h @@ -23,6 +23,7 @@ #define SRSLTE_DYN_BITSET_H #include +#include #include #define CEILFRAC(x, y) (((x) > 0) ? ((((x)-1) / (y)) + 1) : 0) @@ -52,7 +53,7 @@ public: void resize(size_t new_size) noexcept { if (new_size > max_size()) { - printf("ERROR: bitset resize out of bounds: %lu>=%lu\n", max_size(), new_size); + printf("ERROR: bitset resize out of bounds: %zd>=%zd\n", max_size(), new_size); return; } else if (new_size == cur_size) { return; @@ -67,7 +68,7 @@ public: void set(size_t pos) noexcept { if (pos >= size()) { - printf("ERROR: bitset out of bounds: %lu>=%lu\n", pos, size()); + printf("ERROR: bitset out of bounds: %zd>=%zd\n", pos, size()); return; } set_(pos); @@ -76,7 +77,7 @@ public: void reset(size_t pos) noexcept { if (pos >= size()) { - printf("ERROR: bitset out of bounds: %lu>=%lu\n", pos, size()); + printf("ERROR: bitset out of bounds: %zd>=%zd\n", pos, size()); return; } reset_(pos); @@ -92,7 +93,7 @@ public: bool test(size_t pos) const noexcept { if (pos >= size()) { - printf("ERROR: bitset out of bounds: %lu>=%lu\n", pos, size()); + printf("ERROR: bitset out of bounds: %zd>=%zd\n", pos, size()); return false; } return test_(pos); @@ -110,7 +111,7 @@ public: bounded_bitset& fill(size_t startpos, size_t endpos, bool value = true) noexcept { if (endpos > size() or startpos > endpos) { - printf("ERROR: bounds (%lu, %lu) are not valid for bitset of size: %lu\n", startpos, endpos, size()); + printf("ERROR: bounds (%zd, %zd) are not valid for bitset of size: %zd\n", startpos, endpos, size()); return *this; } // NOTE: can be optimized @@ -154,7 +155,7 @@ public: bool any(size_t start, size_t stop) const noexcept { if (start > stop or stop > size()) { - printf("ERROR: bounds (%lu, %lu) are not valid for bitset of size: %lu\n", start, stop, size()); + printf("ERROR: bounds (%zd, %zd) are not valid for bitset of size: %zd\n", start, stop, size()); return false; } // NOTE: can be optimized @@ -198,7 +199,7 @@ public: bounded_bitset& operator|=(const bounded_bitset& other) noexcept { if (other.size() != size()) { - printf("ERROR: operator|= called for bitsets of different sizes (%lu!=%lu)\n", size(), other.size()); + printf("ERROR: operator|= called for bitsets of different sizes (%zd!=%zd)\n", size(), other.size()); return *this; } for (size_t i = 0; i < nof_words_(); ++i) { @@ -210,7 +211,7 @@ public: bounded_bitset& operator&=(const bounded_bitset& other) noexcept { if (other.size() != size()) { - printf("ERROR: operator&= called for bitsets of different sizes (%lu!=%lu)\n", size(), other.size()); + printf("ERROR: operator&= called for bitsets of different sizes (%zd!=%zd)\n", size(), other.size()); return *this; } for (size_t i = 0; i < nof_words_(); ++i) { @@ -249,7 +250,7 @@ public: uint64_t to_uint64() const noexcept { if (nof_words_() > 1) { - printf("ERROR: cannot convert bitset of size %lu bits to uint64_t\n", size()); + printf("ERROR: cannot convert bitset of size %zd bits to uint64_t\n", size()); return 0; } return get_word_(0); @@ -262,7 +263,7 @@ public: size_t count = 0; for (int i = nof_words_() - 1; i >= 0; --i) { - count += sprintf(&cstr[count], "%016lx", buffer[i]); + count += sprintf(&cstr[count], "%016" PRIx64, buffer[i]); } size_t skip = nof_words_() * bits_per_word / 4 - nof_digits; diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 040e5e48a..d45e56d4a 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -20,9 +20,10 @@ */ #include +#include +#include #include #include -#include #include #include @@ -233,7 +234,7 @@ void log_filter::now_time(char* buffer, const uint32_t buffer_len) strncat(buffer, us, buffer_len - dest_len - 1); } else { usec_epoch = rawtime.tv_sec * 1000000 + rawtime.tv_usec; - snprintf(buffer, buffer_len, "%ld", usec_epoch); + snprintf(buffer, buffer_len, "%" PRIu64, usec_epoch); } } else { now = time_src->get_time(); @@ -242,7 +243,7 @@ void log_filter::now_time(char* buffer, const uint32_t buffer_len) snprintf(buffer, buffer_len, "%ld:%06u", now.full_secs, (uint32_t)(now.frac_secs * 1e6)); } else { usec_epoch = now.full_secs * 1000000 + (uint32_t) (now.frac_secs * 1e6); - snprintf(buffer, buffer_len, "%ld", usec_epoch); + snprintf(buffer, buffer_len, "%" PRIu64, usec_epoch); } } } diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index 9fbef8bc9..d3371eb9e 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -19,6 +19,7 @@ * */ +#include #include #include #include @@ -783,7 +784,7 @@ void sch_subh::fprint(FILE* stream) } else { switch (lcid) { case CON_RES_ID: - fprintf(stream, "Contention Resolution ID CE: 0x%lx\n", get_con_res_id()); + fprintf(stream, "Contention Resolution ID CE: 0x%" PRIx64 "\n", get_con_res_id()); break; case TA_CMD: fprintf(stream, "Time Advance Command CE: %d\n", get_ta_cmd()); diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index d7ce26c7d..c0dbb5496 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -19,6 +19,7 @@ * */ +#include #include #include @@ -406,7 +407,7 @@ void ue::allocate_ce(srslte::sch_pdu *pdu, uint32_t lcid) case srslte::sch_subh::CON_RES_ID: if (pdu->new_subh()) { if (pdu->get()->set_con_res_id(conres_id)) { - Info("CE: Added Contention Resolution ID=0x%lx\n", conres_id); + Info("CE: Added Contention Resolution ID=0x%" PRIx64 "\n", conres_id); } else { Error("CE: Setting Contention Resolution ID CE\n"); } diff --git a/srsue/src/phy/sf_worker.cc b/srsue/src/phy/sf_worker.cc index 479a87319..5ad7efda5 100644 --- a/srsue/src/phy/sf_worker.cc +++ b/srsue/src/phy/sf_worker.cc @@ -98,7 +98,7 @@ bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_) goto unlock; } } else { - Error("Setting cell for cc=%d; Not enough CC workers (%ld);\n", cc_idx, cc_workers.size()); + Error("Setting cell for cc=%d; Not enough CC workers (%zd);\n", cc_idx, cc_workers.size()); } if (cc_idx == 0) { diff --git a/srsue/src/stack/mac/proc_ra.cc b/srsue/src/stack/mac/proc_ra.cc index 6033a6f69..0e828322c 100644 --- a/srsue/src/stack/mac/proc_ra.cc +++ b/srsue/src/stack/mac/proc_ra.cc @@ -580,7 +580,7 @@ bool ra_proc::contention_resolution_id_received(uint64_t rx_contention_id) uecri_successful = true; complete(); } else { - rInfo("Transmitted UE Contention Id differs from received Contention ID (0x%lx != 0x%lx)\n", + rInfo("Transmitted UE Contention Id differs from received Contention ID (0x%" PRIx64 " != 0x%" PRIx64 ")\n", transmitted_contention_id, rx_contention_id);