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

Commit a13df307 authored by Spencer Low's avatar Spencer Low
Browse files

adb: refactor _is_valid_ack_reply_fd



Visual Studio's 'jump to reference' feature couldn't parse
adb_commandline() because I used an #ifdef in the middle of an if
statement, so this refactors the code into a separate helper function. I
just copied the code and inverted the comparisons.

No need for sysdeps since this is pretty minor.

Change-Id: Ifd5c62b0b505080ada6db5cc19739c6f07b94de9
Signed-off-by: default avatarSpencer Low <CompareAndSwap@gmail.com>
parent da0b0116
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -931,6 +931,18 @@ static int adb_query_command(const std::string& command) {
    return 0;
}

// Disallow stdin, stdout, and stderr.
static bool _is_valid_ack_reply_fd(const int ack_reply_fd) {
#ifdef _WIN32
    const HANDLE ack_reply_handle = cast_int_to_handle(ack_reply_fd);
    return (GetStdHandle(STD_INPUT_HANDLE) != ack_reply_handle) &&
           (GetStdHandle(STD_OUTPUT_HANDLE) != ack_reply_handle) &&
           (GetStdHandle(STD_ERROR_HANDLE) != ack_reply_handle);
#else
    return ack_reply_fd > 2;
#endif
}

int adb_commandline(int argc, const char **argv) {
    int no_daemon = 0;
    int is_daemon = 0;
@@ -980,14 +992,7 @@ int adb_commandline(int argc, const char **argv) {
            argc--;
            argv++;
            ack_reply_fd = strtol(reply_fd_str, nullptr, 10);
#ifdef _WIN32
            const HANDLE ack_reply_handle = cast_int_to_handle(ack_reply_fd);
            if ((GetStdHandle(STD_INPUT_HANDLE) == ack_reply_handle) ||
                (GetStdHandle(STD_OUTPUT_HANDLE) == ack_reply_handle) ||
                (GetStdHandle(STD_ERROR_HANDLE) == ack_reply_handle)) {
#else
            if (ack_reply_fd <= 2) { // Disallow stdin, stdout, and stderr.
#endif
            if (!_is_valid_ack_reply_fd(ack_reply_fd)) {
                fprintf(stderr, "adb: invalid reply fd \"%s\"\n", reply_fd_str);
                return usage();
            }