Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c5f2b4b authored by Wang Fei's avatar Wang Fei
Browse files

Return default string when sco state string converting

If we do not return the default string, then the return value
will be undefined behavior. Then the bluetooth may be crash.

Test: Restart bluetooth, connect to other remote device,
      then watch if it running OK

Change-Id: Ic578d41ae80ec6a254a42759081dcd115cf6754a
parent 38301895
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -102,6 +102,12 @@ size_t dequeue_packet(const uint8_t** output);

}  // namespace bluetooth::audio::sco::wbs

#ifndef CASE_RETURN_TEXT
#define CASE_RETURN_TEXT(code) \
  case code:                   \
    return #code
#endif

/* Define the structures needed by sco */
typedef enum : uint16_t {
  SCO_ST_UNUSED = 0,
@@ -117,27 +123,23 @@ typedef enum : uint16_t {

inline std::string sco_state_text(const tSCO_STATE& state) {
  switch (state) {
    case SCO_ST_UNUSED:
      return std::string("unused");
    case SCO_ST_LISTENING:
      return std::string("listening");
    case SCO_ST_W4_CONN_RSP:
      return std::string("connect_response");
    case SCO_ST_CONNECTING:
      return std::string("connecting");
    case SCO_ST_CONNECTED:
      return std::string("connected");
    case SCO_ST_DISCONNECTING:
      return std::string("disconnecting");
    case SCO_ST_PEND_UNPARK:
      return std::string("pending_unpark");
    case SCO_ST_PEND_ROLECHANGE:
      return std::string("pending_role_change");
    case SCO_ST_PEND_MODECHANGE:
      return std::string("pending_mode_change");
    CASE_RETURN_TEXT(SCO_ST_UNUSED);
    CASE_RETURN_TEXT(SCO_ST_LISTENING);
    CASE_RETURN_TEXT(SCO_ST_W4_CONN_RSP);
    CASE_RETURN_TEXT(SCO_ST_CONNECTING);
    CASE_RETURN_TEXT(SCO_ST_CONNECTED);
    CASE_RETURN_TEXT(SCO_ST_DISCONNECTING);
    CASE_RETURN_TEXT(SCO_ST_PEND_UNPARK);
    CASE_RETURN_TEXT(SCO_ST_PEND_ROLECHANGE);
    CASE_RETURN_TEXT(SCO_ST_PEND_MODECHANGE);
    default:
      return std::string("unknown_sco_state: ") +
       std::to_string(static_cast<uint16_t>(state));
  }
}

#undef CASE_RETURN_TEXT

/* Define the structure that contains (e)SCO data */
typedef struct {
  tBTM_ESCO_CBACK* p_esco_cback; /* Callback for eSCO events     */