From f1b912d8ed31ebd38baef75ed05f60d97eaff136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 14 Apr 2024 21:19:56 +0200 Subject: [PATCH] adept_loan_mgt: manage cases were name is empty --- utils/adept_loan_mgt.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/adept_loan_mgt.cpp b/utils/adept_loan_mgt.cpp index 22ed6db..ab52d3f 100644 --- a/utils/adept_loan_mgt.cpp +++ b/utils/adept_loan_mgt.cpp @@ -229,7 +229,12 @@ private: maxSizeBookName = loan->bookName.size(); } - if (maxSizeBookName > MAX_SIZE_BOOK_NAME) + /* Manage empty names */ + if (maxSizeBookName == 0) + maxSizeBookName = sizeof("No name ")-1; + else if (maxSizeBookName < 4) + maxSizeBookName = 4; + else if (maxSizeBookName > MAX_SIZE_BOOK_NAME) maxSizeBookName = MAX_SIZE_BOOK_NAME; else if ((maxSizeBookName % 2)) maxSizeBookName++; @@ -276,7 +281,9 @@ private: std::cout << kv.first; std::cout << " "; - if (loan->bookName.size() > MAX_SIZE_BOOK_NAME) + if (loan->bookName.size() == 0) + bookName = std::string("No name "); + else if (loan->bookName.size() > MAX_SIZE_BOOK_NAME) bookName = std::string(loan->bookName.c_str(), MAX_SIZE_BOOK_NAME); else bookName = loan->bookName; -- 2.39.5