33
33
#include " lldb/Utility/DataBufferHeap.h"
34
34
#include " lldb/Utility/DataBufferLLVM.h"
35
35
#include " lldb/Utility/StreamString.h"
36
-
37
-
36
+ #include " llvm/Support/MathExtras.h"
38
37
#include < cinttypes>
39
38
#include < memory>
40
39
@@ -1281,29 +1280,6 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1281
1280
1282
1281
Options *GetOptions () override { return &m_option_group; }
1283
1282
1284
- bool UIntValueIsValidForSize (uint64_t uval64, size_t total_byte_size) {
1285
- if (total_byte_size > 8 )
1286
- return false ;
1287
-
1288
- if (total_byte_size == 8 )
1289
- return true ;
1290
-
1291
- const uint64_t max = ((uint64_t )1 << (uint64_t )(total_byte_size * 8 )) - 1 ;
1292
- return uval64 <= max;
1293
- }
1294
-
1295
- bool SIntValueIsValidForSize (int64_t sval64, size_t total_byte_size) {
1296
- if (total_byte_size > 8 )
1297
- return false ;
1298
-
1299
- if (total_byte_size == 8 )
1300
- return true ;
1301
-
1302
- const int64_t max = ((int64_t )1 << (uint64_t )(total_byte_size * 8 - 1 )) - 1 ;
1303
- const int64_t min = ~(max);
1304
- return min <= sval64 && sval64 <= max;
1305
- }
1306
-
1307
1283
protected:
1308
1284
bool DoExecute (Args &command, CommandReturnObject &result) override {
1309
1285
// No need to check "process" for validity as eCommandRequiresProcess
@@ -1449,7 +1425,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1449
1425
" '%s' is not a valid hex string value.\n " , entry.c_str ());
1450
1426
result.SetStatus (eReturnStatusFailed);
1451
1427
return false ;
1452
- } else if (!UIntValueIsValidForSize (uval64, item_byte_size )) {
1428
+ } else if (!llvm::isUIntN (item_byte_size * 8 , uval64 )) {
1453
1429
result.AppendErrorWithFormat (" Value 0x%" PRIx64
1454
1430
" is too large to fit in a %" PRIu64
1455
1431
" byte unsigned integer value.\n " ,
@@ -1477,7 +1453,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1477
1453
" '%s' is not a valid binary string value.\n " , entry.c_str ());
1478
1454
result.SetStatus (eReturnStatusFailed);
1479
1455
return false ;
1480
- } else if (!UIntValueIsValidForSize (uval64, item_byte_size )) {
1456
+ } else if (!llvm::isUIntN (item_byte_size * 8 , uval64 )) {
1481
1457
result.AppendErrorWithFormat (" Value 0x%" PRIx64
1482
1458
" is too large to fit in a %" PRIu64
1483
1459
" byte unsigned integer value.\n " ,
@@ -1516,7 +1492,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1516
1492
" '%s' is not a valid signed decimal value.\n " , entry.c_str ());
1517
1493
result.SetStatus (eReturnStatusFailed);
1518
1494
return false ;
1519
- } else if (!SIntValueIsValidForSize (sval64, item_byte_size )) {
1495
+ } else if (!llvm::isIntN (item_byte_size * 8 , sval64 )) {
1520
1496
result.AppendErrorWithFormat (
1521
1497
" Value %" PRIi64 " is too large or small to fit in a %" PRIu64
1522
1498
" byte signed integer value.\n " ,
@@ -1535,7 +1511,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1535
1511
entry.c_str ());
1536
1512
result.SetStatus (eReturnStatusFailed);
1537
1513
return false ;
1538
- } else if (!UIntValueIsValidForSize (uval64, item_byte_size )) {
1514
+ } else if (!llvm::isUIntN (item_byte_size * 8 , uval64 )) {
1539
1515
result.AppendErrorWithFormat (" Value %" PRIu64
1540
1516
" is too large to fit in a %" PRIu64
1541
1517
" byte unsigned integer value.\n " ,
@@ -1552,7 +1528,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
1552
1528
" '%s' is not a valid octal string value.\n " , entry.c_str ());
1553
1529
result.SetStatus (eReturnStatusFailed);
1554
1530
return false ;
1555
- } else if (!UIntValueIsValidForSize (uval64, item_byte_size )) {
1531
+ } else if (!llvm::isUIntN (item_byte_size * 8 , uval64 )) {
1556
1532
result.AppendErrorWithFormat (" Value %" PRIo64
1557
1533
" is too large to fit in a %" PRIu64
1558
1534
" byte unsigned integer value.\n " ,
0 commit comments