From 86a0a6d93e336655b5419b233a374a5fe7161e1f Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 19 Dec 2014 12:22:34 +0100 Subject: Fix shortlabel parsing when it's numeric Short labels that were numeric were directly interpreted as a flag, which was undocumented, inconsistent and not very useful. --- src/MuxElements.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/MuxElements.cpp') diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 6ecbcf5..93a98f4 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -98,25 +98,30 @@ int DabLabel::setLabel(const std::string& text, const std::string& short_label) */ int DabLabel::setShortLabel(const std::string& slabel) { - char* end; - const char* lab; - uint16_t flag; - flag = strtoul(slabel.c_str(), &end, 0); - if (*end != 0) { - lab = slabel.c_str(); - flag = 0; - for (int i = 0; i < 32; ++i) { - if (*lab == this->m_text[i]) { - flag |= 0x8000 >> i; - if (*(++lab) == 0) { - break; - } + const char* slab = slabel.c_str(); + uint16_t flag = 0x0; + + /* Iterate over the label and set the bits in the flag + * according to the characters in the slabel + */ + for (int i = 0; i < 32; ++i) { + if (*slab == this->m_text[i]) { + flag |= 0x8000 >> i; + if (*(++slab) == 0) { + break; } } - if (*lab != 0) { - return -1; - } } + + /* If we have remaining characters in the slabel after + * we went through the whole label, the short label + * cannot be represented + */ + if (*slab != 0) { + return -1; + } + + /* Count the number of bits in the flag */ int count = 0; for (int i = 0; i < 16; ++i) { if (flag & (1 << i)) { -- cgit v1.2.3