diff --git a/system/core/devmgr/devhost/devhost.cpp b/system/core/devmgr/devhost/devhost.cpp index a507c835d07cd03a0ba629e27c9e4b345e8daab6..818405c1ec9ae17ac8d2645df20b2a711a3cdf99 100644 --- a/system/core/devmgr/devhost/devhost.cpp +++ b/system/core/devmgr/devhost/devhost.cpp @@ -799,13 +799,16 @@ static ssize_t devhost_log_write_internal(uint32_t flags, const void* void_data, const char* data = static_cast<const char*>(void_data); size_t r = len; + auto flush_context = [&]() { + ctx->handle->write(flags, ctx->data, ctx->next); + ctx->next = 0; + }; + while (len-- > 0) { char c = *data++; if (c == '\n') { if (ctx->next) { -flush_ctx: - ctx->handle->write(flags, ctx->data, ctx->next); - ctx->next = 0; + flush_context(); } continue; } @@ -814,7 +817,7 @@ flush_ctx: } ctx->data[ctx->next++] = c; if (ctx->next == LOGBUF_MAX) { - goto flush_ctx; + flush_context(); } } return r; diff --git a/system/core/devmgr/devhost/rpc-server.cpp b/system/core/devmgr/devhost/rpc-server.cpp index 766fb65d9b16a8a91bd23cc37a0ceeaf0af4aede..cb2c562aa0687a93bea46d39d85c19f868e5d061 100644 --- a/system/core/devmgr/devhost/rpc-server.cpp +++ b/system/core/devmgr/devhost/rpc-server.cpp @@ -494,12 +494,15 @@ static zx_status_t fidl_file_writeat(void* ctx, const uint8_t* data, size_t coun static zx_status_t fidl_file_seek(void* ctx, int64_t offset, fuchsia_io_SeekOrigin start, fidl_txn_t* txn) { auto conn = static_cast<DevfsConnection*>(ctx); - size_t end, n; - end = conn->dev->GetSizeOp(); + auto bad_args = [&]() { + return fuchsia_io_FileSeek_reply(txn, ZX_ERR_INVALID_ARGS, 0); + }; + size_t end = conn->dev->GetSizeOp(); + size_t n; switch (start) { case fuchsia_io_SeekOrigin_START: if ((offset < 0) || ((size_t)offset > end)) { - goto bad_args; + return bad_args(); } n = offset; break; @@ -511,13 +514,13 @@ static zx_status_t fidl_file_seek(void* ctx, int64_t offset, fuchsia_io_SeekOrig // if negative seek if (n > conn->io_off) { // wrapped around - goto bad_args; + return bad_args(); } } else { // positive seek if (n < conn->io_off) { // wrapped around - goto bad_args; + return bad_args(); } } break; @@ -527,27 +530,24 @@ static zx_status_t fidl_file_seek(void* ctx, int64_t offset, fuchsia_io_SeekOrig // if negative or exact-end seek if (n > end) { // wrapped around - goto bad_args; + return bad_args(); } } else { if (n < end) { // wrapped around - goto bad_args; + return bad_args(); } } break; default: - goto bad_args; + return bad_args(); } if (n > end) { // devices may not seek past the end - goto bad_args; + return bad_args(); } conn->io_off = n; return fuchsia_io_FileSeek_reply(txn, ZX_OK, conn->io_off); - -bad_args: - return fuchsia_io_FileSeek_reply(txn, ZX_ERR_INVALID_ARGS, 0); } static zx_status_t fidl_file_truncate(void* ctx, uint64_t length, fidl_txn_t* txn) {