Fix a bunch of uses of 'short'.
(In particular, port numbers should be unsigned short.)
Change-Id: I944eb0f8e97390f1af8094b07ee7f2a00045bd35
diff --git a/jdwpspy/Common.h b/jdwpspy/Common.h
index ddaba9c..f942dee 100644
--- a/jdwpspy/Common.h
+++ b/jdwpspy/Common.h
@@ -6,13 +6,14 @@
#ifndef _JDWPSPY_COMMON
#define _JDWPSPY_COMMON
+#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
-typedef unsigned char u1;
-typedef unsigned short u2;
-typedef unsigned int u4;
-typedef unsigned long long u8;
+typedef uint8_t u1;
+typedef uint16_t u2;
+typedef uint32_t u4;
+typedef uint64_t u8;
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/jdwpspy/Net.cpp b/jdwpspy/Net.cpp
index eea21c8..209cf28 100644
--- a/jdwpspy/Net.cpp
+++ b/jdwpspy/Net.cpp
@@ -53,7 +53,7 @@
/* connect here to contact VM */
struct in_addr vmAddr;
- short vmPort;
+ uint16_t vmPort;
Peer dbg;
Peer vm;
@@ -227,9 +227,7 @@
*
* Returns 0 on success.
*/
-NetState* jdwpNetStartup(unsigned short listenPort, const char* connectHost,
- unsigned short connectPort)
-{
+NetState* jdwpNetStartup(uint16_t listenPort, const char* connectHost, uint16_t connectPort) {
NetState* netState = new NetState;
memset(netState, 0, sizeof(*netState));
netState->listenSock = -1;
diff --git a/src/globals.h b/src/globals.h
index e5fead6..e5b0075 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -15,22 +15,13 @@
const size_t KB = 1024;
const size_t MB = KB * KB;
const size_t GB = KB * KB * KB;
-const int kMaxInt = 0x7FFFFFFF;
-const int kMinInt = -kMaxInt - 1;
-const int kCharSize = sizeof(char);
-const int kShortSize = sizeof(short);
-const int kIntSize = sizeof(int);
-const int kDoubleSize = sizeof(double);
-const int kIntptrSize = sizeof(intptr_t);
const int kWordSize = sizeof(word);
const int kPointerSize = sizeof(void*);
const int kBitsPerByte = 8;
const int kBitsPerByteLog2 = 3;
-const int kBitsPerPointer = kPointerSize * kBitsPerByte;
const int kBitsPerWord = kWordSize * kBitsPerByte;
-const int kBitsPerInt = kIntSize * kBitsPerByte;
// Required stack alignment
const int kStackAlignment = 16;
diff --git a/src/jdwp/jdwp.h b/src/jdwp/jdwp.h
index 03c70b0..ad3d077 100644
--- a/src/jdwp/jdwp.h
+++ b/src/jdwp/jdwp.h
@@ -95,7 +95,7 @@
bool server;
bool suspend;
std::string host;
- short port;
+ uint16_t port;
};
struct JdwpEvent;
diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc
index d28c1da..d3677e8 100644
--- a/src/jdwp/jdwp_socket.cc
+++ b/src/jdwp/jdwp_socket.cc
@@ -55,12 +55,12 @@
* We only talk to one debugger at a time.
*/
struct JdwpNetState : public JdwpNetStateBase {
- short listenPort;
+ uint16_t listenPort;
int listenSock; /* listen for connection from debugger */
int wakePipe[2]; /* break out of select */
struct in_addr remoteAddr;
- unsigned short remotePort;
+ uint16_t remotePort;
bool awaitingHandshake; /* waiting for "JDWP-Handshake" */
@@ -80,18 +80,17 @@
}
};
-static JdwpNetState* netStartup(short port, bool probe);
+static JdwpNetState* netStartup(uint16_t port, bool probe);
/*
* Set up some stuff for transport=dt_socket.
*/
static bool prepareSocket(JdwpState* state, const JdwpOptions* options) {
- unsigned short port;
+ uint16_t port = options->port;
if (options->server) {
if (options->port != 0) {
/* try only the specified port */
- port = options->port;
state->netState = netStartup(port, false);
} else {
/* scan through a range of ports, binding to the first available */
@@ -107,8 +106,7 @@
return false;
}
} else {
- port = options->port; // used in a debug msg later
- state->netState = netStartup(-1, false);
+ state->netState = netStartup(0, false);
}
if (options->suspend) {
@@ -130,8 +128,8 @@
/*
* Initialize JDWP stuff.
*
- * Allocates a new state structure. If "port" is non-negative, this also
- * tries to bind to a listen port. If "port" is less than zero, we assume
+ * Allocates a new state structure. If "port" is non-zero, this also
+ * tries to bind to a listen port. If "port" is zero, we assume
* we're preparing for an outbound connection, and return without binding
* to anything.
*
@@ -139,15 +137,12 @@
*
* Returns 0 on success.
*/
-static JdwpNetState* netStartup(short port, bool probe) {
- int one = 1;
+static JdwpNetState* netStartup(uint16_t port, bool probe) {
JdwpNetState* netState = new JdwpNetState;
- if (port < 0) {
+ if (port == 0) {
return netState;
}
- CHECK_NE(port, 0);
-
netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (netState->listenSock < 0) {
PLOG(probe ? ERROR : FATAL) << "Socket create failed";
@@ -155,9 +150,12 @@
}
/* allow immediate re-use */
- if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
- PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed";
- goto fail;
+ {
+ int one = 1;
+ if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
+ PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed";
+ goto fail;
+ }
}
union {