From 99bb50bf5410eadf1bd301c1e6982c5884964b7e Mon Sep 17 00:00:00 2001
From: wangyanwen <wangyanwen@nucleisys.com>
Date: Mon, 9 Oct 2023 14:08:59 +0800
Subject: [PATCH] server/gdb-server:fix flash operation error when addr-width >
 32bit on windows.

Change-Id: I199f1cc5128c45bd0bb155e37acb2fb6325dff88
---
 src/server/gdb_server.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index cdb26f245..cc808c9ad 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -3305,8 +3305,8 @@ static int gdb_v_packet(struct connection *connection,
 	}
 
 	if (strncmp(packet, "vFlashErase:", 12) == 0) {
-		unsigned long addr;
-		unsigned long length;
+		target_addr_t addr;
+		target_addr_t length;
 
 		char const *parse = packet + 12;
 		if (*parse == '\0') {
@@ -3314,14 +3314,14 @@ static int gdb_v_packet(struct connection *connection,
 			return ERROR_SERVER_REMOTE_CLOSED;
 		}
 
-		addr = strtoul(parse, (char **)&parse, 16);
+		addr = strtoull(parse, (char **)&parse, 16);
 
 		if (*(parse++) != ',' || *parse == '\0') {
 			LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
 			return ERROR_SERVER_REMOTE_CLOSED;
 		}
 
-		length = strtoul(parse, (char **)&parse, 16);
+		length = strtoull(parse, (char **)&parse, 16);
 
 		if (*parse != '\0') {
 			LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
@@ -3362,15 +3362,16 @@ static int gdb_v_packet(struct connection *connection,
 
 	if (strncmp(packet, "vFlashWrite:", 12) == 0) {
 		int retval;
-		unsigned long addr;
-		unsigned long length;
+		target_addr_t addr;
+		target_addr_t length;
 		char const *parse = packet + 12;
 
 		if (*parse == '\0') {
 			LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
 			return ERROR_SERVER_REMOTE_CLOSED;
 		}
-		addr = strtoul(parse, (char **)&parse, 16);
+
+		addr = strtoull(parse, (char **)&parse, 16);
 		if (*(parse++) != ':') {
 			LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
 			return ERROR_SERVER_REMOTE_CLOSED;
-- 
2.41.0.windows.3

