X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Ftestclient%2Fmain.cpp;h=983ba13736fff90d6b3b16c9fce8985206ead71c;hb=8bca69de10349c3cfb7ea3ba4ab5f7ebbb34a740;hp=f2f2bf3e0a9678338fc8b347b38d6afc853b0006;hpb=b9861f8c07b62dd45657df91debe3dadc2654e9c;p=deb_libcec.git diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index f2f2bf3..983ba13 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -45,11 +45,23 @@ using namespace std; #define CEC_TEST_CLIENT_VERSION 3 -inline bool HexStrToInt(const std::string& data, int& value) +inline bool HexStrToInt(const std::string& data, uint8_t& value) { - return sscanf(data.c_str(), "%x", &value) == 1; -} + int iTmp(0); + if (sscanf(data.c_str(), "%x", &iTmp) == 1) + { + if (iTmp > 256) + value = 255; + else if (iTmp < 0) + value = 0; + else + value = (uint8_t) iTmp; + return true; + } + + return false; +} //get the first word (separated by whitespace) from string data and place that in word //then remove that word from string data @@ -254,7 +266,7 @@ int main (int argc, char *argv[]) if (command == "tx") { string strvalue; - int ivalue; + uint8_t ivalue; vector bytes; while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue)) bytes.push_back(ivalue);