Re: Logging with a string via %s


"K.I.R.A.
 

sprintf(baTmpBuf, "%s", "ffffffff"); ?

---Original---
From: "lairdjm"<jamie.mccrae@...>
Date: Wed, May 15, 2019 18:52 PM
To: "devel@..."<devel@...>;
Subject: [Zephyr-devel] Logging with a string via %s

Hi,

I’m seeing an issue whereby I am unable to log strings using LOG_DBG() and %s format, for a quick example I modified the hello world sample to enable logging and change the code to this:

#define LOG_DOMAIN test_domain

#include <logging/log.h>

LOG_MODULE_REGISTER(LOG_DOMAIN);

 

void main(void)

{

               char baTmpBuf[12];

               sprintf(baTmpBuf, "ffffffff");

               LOG_DBG("Test : %s", baTmpBuf);

 

               printk("Hello World! %s\n", CONFIG_BOARD);

}

I expect to see “Test : ffffffff” but instead I am getting “Test : %*”, if I change the code to inefficiently log each character, e.g.:

                LOG_DBG("Test : %c%c%c%c%c%c%c%c", baTmpBuf[0], baTmpBuf[1], baTmpBuf[2], baTmpBuf[3], baTmpBuf[4], baTmpBuf[5], baTmpBuf[6], baTmpBuf[7]);

Then I get the expected output: “Test : ffffffff

 

So why is %s not outputting a string? If there a configuration option I have missed? I have tried toggling “Format strings with libc” option but it doesn’t change anything. I’m testing on an nRF52840 using the nrf52840_pca10056 board file.

Thanks,
Jamie

THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.

Join devel@lists.zephyrproject.org to automatically receive all group messages.