Bug Summary

File:tools/lldb/source/Host/common/UDPSocket.cpp
Warning:line 132, column 3
Value stored to 'err' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name UDPSocket.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/source/Host -I /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/source/Host -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/source/. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/source/Host -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/source/Host/common/UDPSocket.cpp -faddrsig
1//===-- UDPSocket.cpp -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Host/common/UDPSocket.h"
11
12#include "lldb/Host/Config.h"
13#include "lldb/Utility/Log.h"
14
15#ifndef LLDB_DISABLE_POSIX
16#include <arpa/inet.h>
17#include <sys/socket.h>
18#endif
19
20#include <memory>
21
22using namespace lldb;
23using namespace lldb_private;
24
25namespace {
26
27const int kDomain = AF_INET2;
28const int kType = SOCK_DGRAMSOCK_DGRAM;
29
30static const char *g_not_supported_error = "Not supported";
31}
32
33UDPSocket::UDPSocket(NativeSocket socket) : Socket(ProtocolUdp, true, true) {
34 m_socket = socket;
35}
36
37UDPSocket::UDPSocket(bool should_close, bool child_processes_inherit)
38 : Socket(ProtocolUdp, should_close, child_processes_inherit) {}
39
40size_t UDPSocket::Send(const void *buf, const size_t num_bytes) {
41 return ::sendto(m_socket, static_cast<const char *>(buf), num_bytes, 0,
42 m_sockaddr, m_sockaddr.GetLength());
43}
44
45Status UDPSocket::Connect(llvm::StringRef name) {
46 return Status("%s", g_not_supported_error);
47}
48
49Status UDPSocket::Listen(llvm::StringRef name, int backlog) {
50 return Status("%s", g_not_supported_error);
51}
52
53Status UDPSocket::Accept(Socket *&socket) {
54 return Status("%s", g_not_supported_error);
55}
56
57Status UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit,
58 Socket *&socket) {
59 std::unique_ptr<UDPSocket> final_socket;
60
61 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION(1u << 13)));
62 if (log)
63 log->Printf("UDPSocket::%s (host/port = %s)", __FUNCTION__, name.data());
64
65 Status error;
66 std::string host_str;
67 std::string port_str;
68 int32_t port = INT32_MIN(-2147483647-1);
69 if (!DecodeHostAndPort(name, host_str, port_str, port, &error))
70 return error;
71
72 // At this point we have setup the receive port, now we need to setup the UDP
73 // send socket
74
75 struct addrinfo hints;
76 struct addrinfo *service_info_list = nullptr;
77
78 ::memset(&hints, 0, sizeof(hints));
79 hints.ai_family = kDomain;
80 hints.ai_socktype = kType;
81 int err = ::getaddrinfo(host_str.c_str(), port_str.c_str(), &hints,
82 &service_info_list);
83 if (err != 0) {
84 error.SetErrorStringWithFormat(
85#if defined(_MSC_VER) && defined(UNICODE)
86 "getaddrinfo(%s, %s, &hints, &info) returned error %i (%S)",
87#else
88 "getaddrinfo(%s, %s, &hints, &info) returned error %i (%s)",
89#endif
90 host_str.c_str(), port_str.c_str(), err, gai_strerror(err));
91 return error;
92 }
93
94 for (struct addrinfo *service_info_ptr = service_info_list;
95 service_info_ptr != nullptr;
96 service_info_ptr = service_info_ptr->ai_next) {
97 auto send_fd = CreateSocket(
98 service_info_ptr->ai_family, service_info_ptr->ai_socktype,
99 service_info_ptr->ai_protocol, child_processes_inherit, error);
100 if (error.Success()) {
101 final_socket.reset(new UDPSocket(send_fd));
102 final_socket->m_sockaddr = service_info_ptr;
103 break;
104 } else
105 continue;
106 }
107
108 ::freeaddrinfo(service_info_list);
109
110 if (!final_socket)
111 return error;
112
113 SocketAddress bind_addr;
114
115 // Only bind to the loopback address if we are expecting a connection from
116 // localhost to avoid any firewall issues.
117 const bool bind_addr_success = (host_str == "127.0.0.1" || host_str == "localhost")
118 ? bind_addr.SetToLocalhost(kDomain, port)
119 : bind_addr.SetToAnyAddress(kDomain, port);
120
121 if (!bind_addr_success) {
122 error.SetErrorString("Failed to get hostspec to bind for");
123 return error;
124 }
125
126 bind_addr.SetPort(0); // Let the source port # be determined dynamically
127
128 err = ::bind(final_socket->GetNativeSocket(), bind_addr, bind_addr.GetLength());
129
130 struct sockaddr_in source_info;
131 socklen_t address_len = sizeof (struct sockaddr_in);
132 err = ::getsockname(final_socket->GetNativeSocket(), (struct sockaddr *) &source_info, &address_len);
Value stored to 'err' is never read
133
134 socket = final_socket.release();
135 error.Clear();
136 return error;
137}