J-D-K / JKSV

JK's Save Manager Switch Edition
GNU General Public License v3.0
1.3k stars 99 forks source link

Year Month Day date format missing from autocomplete suggestions #114

Closed zand closed 2 years ago

zand commented 2 years ago

Environment

OS Version: 12.1.0|AMS M.19.5|E Serial: XAW10035xxxxxx JKSM Version: 08.01.2021

Steps to reproduce

  1. Launch JKSV from the Homebrew Menu in Applet Mode
  2. Select Device Saves and press A
  3. Select Animal Crossing: New Horizons and press A
  4. Leave New selected and press A
  5. Input a "2"

Expected Result

The YYYY.DD.MM @ hh.mm.ss date format to be listed as one of the suggestions.

Actual Result

The suggestions above the keyboard show the date in the YYYYMMD_hhmm and YYYY.DD.MM @ hh.mm.ss format but not YYYY.DD.MM @ hh.mm.ss.

Things to note

I manage to track the down the point that the bug happens by making the following changes below

diff --git a/src/util.cpp b/src/util.cpp
index 13fd8a4..bd7998c 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -254,7 +254,20 @@ std::string util::getStringInput(const std::string& def, const std::string& head
     {
         dictWord words[dictCnt];
         for(unsigned i = 0; i < dictCnt; i++)
+       {
             swkbdDictWordCreate(&words[i], dictWords[i].c_str(), dictWords[i].c_str());
+           fs::logWrite("%04x ", words[0].read[0]);
+        }
+
+        fs::logWrite("\nwords:\n");
+       for (unsigned i = 0; i < dictCnt; i++)
+       {
+         uint16_t* ptr = (uint16_t *)&words[i];
+          for(unsigned ii = 0; ii<sizeof(dictWord); ii++)
+            fs::logWrite("%04x ", ptr[ii]);
+
+         fs::logWrite("\n");
+       }

         swkbdConfigSetDictionary(&swkbd, (SwkbdDictWord *)words, dictCnt);
     }

Witch results in the following in the log

0032 0032 0032 0032 0032 0032 0073 0073 
words:
0073 0030 0032 0031 002e 0030 0038 002e 0030 0032 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 0032 0030 0032 0031 002e 0030 0038 002e 0030 0032 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 0032 0030 0032 0031 002e 0030 0032 002e 0030 0038 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 0032 0030 0032 0031 002e 0030 0032 002e 0030 0038 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 
0032 0030 0032 0031 002e 0030 0032 002e 0030 0038 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 0032 0030 0032 0031 002e 0030 0032 002e 0030 0038 0020 0040 0020 0032 0032 002e 0035 0038 002e 0035 0031 0000 0000 0000 0000 0030 0032 002e 0030 0038 002e 0032 0030 0032 0031 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0030 0032 002e 0030 0038 002e 0032 0030 0032 0031 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
0030 0032 002e 0030 0038 002e 0032 0030 0032 0031 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0030 0032 002e 0030 0038 002e 0032 0030 0032 0031 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0032 0030 0032 0031 0030 0038 0030 0032 005f 0032 0032 0035 0038 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0032 0030 0032 0031 0030 0038 0030 0032 005f 0032 0032 0035 0038 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
0032 0030 0032 0031 0030 0038 0030 0032 005f 0032 0032 0035 0038 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0032 0030 0032 0031 0030 0038 0030 0032 005f 0032 0032 0035 0038 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 004d 006f 006e 0020 0041 0075 0067 0020 0020 0032 0020 0032 0032 005f 0035 0038 005f 0035 0031 0020 0032 0030 0032 0031 0000 004d 006f 006e 0020 0041 0075 0067 0020 0020 0032 0020 0032 0032 005f 0035 0038 005f 0035 0031 0020 0032 0030 0032 0031 0000 
004d 006f 006e 0020 0041 0075 0067 0020 0020 0032 0020 0032 0032 005f 0035 0038 005f 0035 0031 0020 0032 0030 0032 0031 0000 004d 006f 006e 0020 0041 0075 0067 0020 0020 0032 0020 0032 0032 005f 0035 0038 005f 0035 0031 0020 0032 0030 0032 0031 0000 0044 0065 0076 0069 0063 0065 0020 0053 0061 0076 0065 0073 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0044 0065 0076 0069 0063 0065 0020 0053 0061 0076 0065 0073 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
0044 0065 0076 0069 0063 0065 0020 0053 0061 0076 0065 0073 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0044 0065 0076 0069 0063 0065 0020 0053 0061 0076 0065 0073 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0041 006e 0069 006d 0061 006c 0020 0043 0072 006f 0073 0073 0069 006e 0067 0020 0020 004e 0065 0077 0020 0048 006f 0072 0000 0041 006e 0069 006d 0061 006c 0020 0043 0072 006f 0073 0073 0069 006e 0067 0020 0020 004e 0065 0077 0020 0048 006f 0072 0000 
0041 006e 0069 006d 0061 006c 0020 0043 0072 006f 0073 0073 0069 006e 0067 0020 0020 004e 0065 0077 0020 0048 006f 0072 0000 0041 006e 0069 006d 0061 006c 0020 0043 0072 006f 0073 0073 0069 006e 0067 0020 0020 004e 0065 0077 0020 0048 006f 0072 0000 0041 0043 004e 0048 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0041 0043 004e 0048 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
0041 0043 004e 0048 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0041 0043 004e 0048 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 4d60 9266 001f 0000 b474 74e8 0016 0000 4f80 9266 001f 0000 4e70 9266 001f 0000 4df0 9266 001f 0000 4ea0 9266 001f 0000 b000 7567 0016 0000 c000 7567 0016 0000 4e90 9266 001f 0000 4e80 9266 001f 0000 4e50 9266 001f 0000 0090 0000 0000 0000 47ca 9266

Note that the first line in the log shows that the first byte of words changes from 0x32 to 0x73 durring the loop. https://github.com/J-D-K/JKSV/blob/de3585dbc3c84d4832bb9291cfe9bb5e49c39a74/src/util.cpp#L256-L257

I was unable to figure out why this happens but inputting a "s" instead of "2" results the date being suggested in YYYY.DD.MM @ hh.mm.ss format. A couple of my guesses are is it's a bug in a different thread or flaw in my switch's hardware. So far, I been able to reproduce it 100% time and it would be interesting to find out if the switch hardware is a factor.

zand commented 2 years ago

Another thought is that the autocomplete lists "Animal Crossing New Hor" and it might be possible that the 0x73 somehow comes from the "s" on the end of "Animal Crossing New Horizons".

zand commented 2 years ago

Managed to determine that the bug is with the call to utf8_to_utf16 and is a result of passing strings longer than 25 characters to it while handing it a 50 byte buffer witch every char after the 25th one overflows the buffer.

J-D-K commented 2 years ago

Hey. Sorry. I'm not ignoring you or your pull requests. I want to focus on getting the new UI branch sorta finished and merged, then we can check this out and get it all sorted.

zand commented 2 years ago

No problem, I changed the commit messages to be less verbose and to simple state what was done. I also created a new branch from newUI https://github.com/J-D-K/JKSV/compare/newUI...zand:newUI-iss114 and applied the changes to that in case that helps.

J-D-K commented 2 years ago

OK thank you. I just pulled the fix from your last comment to the newUI branch. It didn't add you as a contributor but I'll add it to the readme if you'd like.