Reland "Prevent unsafe narrowing: base/ for Linux part 2 of n"

Bug: 1292951
Change-Id: I2ba0e069a26ebac13dcd4ae162764d28d90f4a73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3758876
Reviewed-by: danakj <[email protected]>
Owners-Override: danakj <[email protected]>
Commit-Queue: Peter Kasting <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1024348}
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc
index 92d47fc..1b75de7 100644
--- a/base/sync_socket_posix.cc
+++ b/base/sync_socket_posix.cc
@@ -23,6 +23,7 @@
 #include "base/check_op.h"
 #include "base/containers/span.h"
 #include "base/files/file_util.h"
+#include "base/numerics/safe_conversions.h"
 #include "base/threading/scoped_blocking_call.h"
 #include "build/build_config.h"
 
@@ -174,8 +175,7 @@
     // If there is an error in ioctl, signal that the channel would block.
     return 0;
   }
-  DCHECK_GE(number_chars, 0);
-  return number_chars;
+  return checked_cast<size_t>(number_chars);
 }
 
 bool SyncSocket::IsValid() const {