From 4c9a9519592de60f2d8d390c9c09ec2ed1ba30fe Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Wed, 13 Dec 2023 09:02:39 +0000 Subject: [PATCH] fix: fix some small problems in lexer --- backend/src/lexer.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index 1af67f4..8f0d7c8 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -277,7 +277,10 @@ bool CommandBuyLexer(const std::string &command, std::string &ISBN, ISBN = ""; quantity = 0; ss >> ISBN; - ss >> quantity; + long long quantity_tmp = 0; + ss >> quantity_tmp; + if (quantity_tmp > 2147483647) return false; + quantity = quantity_tmp; return true; } else return false; @@ -388,7 +391,10 @@ bool CommandImportLexer(const std::string &command, int &quantity, ss >> token; quantity = 0; total_cost = 0; - ss >> quantity; + long long quantity_tmp = 0; + ss >> quantity_tmp; + if (quantity_tmp > 2147483647) return false; + quantity = quantity_tmp; ss >> total_cost; return true; } else @@ -416,8 +422,10 @@ bool CommandShowfinanceLexer(const std::string &command, int &count) { std::stringstream ss(command); std::string token; ss >> token; - count = -1; - ss >> count; + long long count_tmp = -1; + ss >> count_tmp; + if (count_tmp > 2147483647) return false; + count = count_tmp; return true; } else return false;