Strange Error Message from PlatformIO When I try to Build my Marlin

I taught myself to use VSCode and PlatformIO, then compiled a fresh Marlin from scratch for my custom built printer that has a BigTreeTech SKR 1.4 Turbo board with a TFT35 touchscreen controller, which took me 3 weeks to compile. I finally got the printer working properly and I have been very happy. …Move forward in time approx. 1 year … Lately I decided to make a slight change and to add sensorless homing on the X + Y axis’s, so I ordered and received my new TMC 2209’s from BigTreeTech, then I opened my VSCode and decided to compile my old Marlin before making any changes, just to make sure it was ok. Now I am getting this message: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]

I have another version for my other printer that I worked on at the same time but that one is fine.

I have no idea how to fix this and I can’t find any help except this one page in this forum. Can someone please tell me how to fix this??

You can download and test my Marlin from my Google Drive link: 0. Marlin for ELF – Google Drive

Thanks !!

1 Like

Trying to download + clean + build your project just gives me

Marlin\src\HAL\AVR\../../inc/../pins/lpc1769/../lpc1768/pins_BTT_SKR_common.h:26:6: error: #error "Oops! Make sure you have the LPC1769 environment selected in your IDE."

Do you use Marlin Auto Builder to build the firmware? What environment in the platformio.ini are you using?

What does that mean? Environment? Do you mean do I use lpc1769 to build it ?? Then Yes. No I didn’t use the Marlin Auto Builder, (but I just installed it and tried it and I get the same message). I figured it all out on my own before. It worked perfectly and still works on my other printer build that has the same board but different configurations. I just get this weird message and it won’t build, but I never changed anything. But there is some missing letters I missed at the end that I just noticed. The whole message I get is: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=] [Ln 130, Col 105]

Okay because you have set default_envs = mega2560 (or let it be at its default) in the project files you uploaded. You must have used the project tasks explorer then to press the “Build” button in your LPC1769 environment. That is very crucial information that was missing – Marlin has a hundred environments ([env:xyz in platformio.ini) and for reproduction we need to know which exact one you’re using.

Back to the error – When I compille, I get

Compiling .pio\build\LPC1769\src\src\lcd\menu\menu_custom.cpp.o
In file included from c:\users\max\.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\c++\10.3.1\functional:56,
                 from c:\users\max\.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\c++\10.3.1\pstl\glue_algorithm_defs.h:13,
                 from c:\users\max\.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\c++\10.3.1\algorithm:74,
                 from Marlin\src\lcd\../inc/../HAL/./LPC1768/HAL.h:35,
                 from Marlin\src\lcd\../inc/../HAL/HAL.h:26,
                 from Marlin\src\lcd\../inc/MarlinConfig.h:31,
                 from Marlin\src\lcd\lcdprint.h:35,
                 from Marlin\src\lcd\lcdprint.cpp:31:
c:\users\max\.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\c++\10.3.1\bits\functional_hash.h:168:3: error: redefinition of 'struct std::hash<long unsigned int>'
  168 |   _Cxx_hashtable_define_trivial_hash(unsigned long)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\users\max\.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\c++\10.3.1\bits\functional_hash.h:136:3: note: previous definition of 'struct std::hash<long unsigned int>'
  136 |   _Cxx_hashtable_define_trivial_hash(wchar_t)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So it may you have an older toolchain than me?

I am really sorry, but like I said, I taught myself, basically to just push the right buttons like a monkey. I have absolutely no clue what any of that means. It used to build, and now it won’t. I even replaced the complete duration_t.h file with an older build I kept that worked, that just didn’t have the BLTouch configured, and I get the same error every time. (this is the original duration file here).

I think it’s best to start with a fresh + latest copy of Marlin and compile it without modifications, then back in the modifications (which hopefully you have made a list of what those were in the previous version).

If in doubt, you can ask the Marlin people for help Issues · MarlinFirmware/Marlin · GitHub, e.g. on the Discord server).

Just making sure though: Is that error message where it fails compilation at the end with a big fat red “=== FAILED ====” message or is this just a yellow warning? The latter doesn’t really matter.

Technically, sprintf should not be used anyways, but rather snprintf, since that has a maximum buffer length as a parameter.

See also Warning Options (Using the GNU Compiler Collection (GCC)) starting at " -Wformat-overflow" for technical information.

Nice link, but it’s all Greek to me. And yes, the error message is a big fat red one, I ignore the few yellow ones. It was never there before, but it is now. You don’t know the BS I had to go through to get this working. Took me 4-6 hours a day over a 3 week period to learn all this and get it to build and work from a fresh build of Marlin. And yes I kept all my mods, but I was really hoping that I didn’t have to go through all that again for one simple error message. Thanks anyways. I appreciate your help.

Could open PlatformIO CLI in VSCode (see PIO docs for VSCode), and type

pio upgrade --dev

Does it work?

I appreciate you trying to help but I have no clue what you are asking about.

Getting into the CLI is described in the docs, specifically PlatformIO IDE for VSCode — PlatformIO latest documentation.

But since this is a code compile error regarding possibly-bad sprintf usage in a possibly old Marlin version, I don’t think this would help.

Well, thank you anyways. I do appreciate the attempt to help. I guess a Marlin version over a year old is considered “Old” in this day and age. I have already surrendered myself to the fact that I am going to have to completely rebuild my Marlin for this printer from scratch using a new Marlin. I just have to make myself sit down and actually do it.
Thanks again!