va_list returns something wrong

elektron314
Posts: 7
Joined: Wed Oct 27, 2021 5:15 pm

va_list returns something wrong

Postby elektron314 » Mon Nov 15, 2021 8:25 am

Hi! I have very strange behaviour of my code. I don't undestand where is the problem.
Here I have vprintf-like function by wich I substitute output of in ESP_LOGe in
  1. esp_log_set_vprintf(vprintf_like_t_sw_uart_write);
This is implementation
  1. int vprintf_like_t_sw_uart_write(const char *format, va_list args)
  2. {
  3.     char buffer[100];
  4.     sprintf(buffer, format, args);
  5.     return sw_uart_write(buffer);
  6. }
Where sw_uart_write is my own function that create one more software uart (bitbanging).
So if I write e.g.
  1. arg = 0;
  2. ESP_LOGE("TAG", "esp_loge test %d", arg);
I see this in my software uart output:
esp_loge test 12
Whatever put instead of arg I always get 12.
What can be wrong?
My sw_uart_write works ok. It's just simple bitbanging.

elektron314
Posts: 7
Joined: Wed Oct 27, 2021 5:15 pm

Re: va_list returns something wrong

Postby elektron314 » Mon Nov 15, 2021 11:30 am

UPDATE:
even this function being set as esp_log_set_vprintf(vprintf_like); always transform my args to int 12
  1. int vprintf_like(const char *format, va_list args)
  2. {
  3.     return printf(format, args);
  4. }

elektron314
Posts: 7
Joined: Wed Oct 27, 2021 5:15 pm

Re: va_list returns something wrong

Postby elektron314 » Mon Nov 15, 2021 11:39 am

Somebody help me.
  1. esp_log_set_vprintf(printf);
transforms arguments to int 12
usage:
  1. ESP_LOGE("TAG", "??? main -----------%d",999);
results in printing
??? main -----------12

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: va_list returns something wrong

Postby boarchuz » Mon Nov 15, 2021 12:39 pm

You can't forward the va_list to sprintf. Try vsprintf.

elektron314
Posts: 7
Joined: Wed Oct 27, 2021 5:15 pm

Re: va_list returns something wrong

Postby elektron314 » Mon Nov 15, 2021 1:31 pm

boarchuz wrote:
Mon Nov 15, 2021 12:39 pm
You can't forward the va_list to sprintf. Try vsprintf.
Thanks! It works, you are right!

Who is online

Users browsing this forum: federicolonghin and 82 guests