os_bzero() detecting correct length issue

FrenkR
Posts: 42
Joined: Thu Dec 04, 2014 9:25 am

os_bzero() detecting correct length issue

Postby FrenkR » Tue Sep 06, 2016 5:04 pm

Hi,
using SDK 2.0 with latest patch.
it seems that os_bzero() in some cases can't recognize correct structure length. I have following situation:

Code: Select all

   struct station_config * confSTA;
   confSTA = (struct station_config *) os_zalloc(sizeof(struct station_config));
   
    wifi_station_get_config(confSTA);
   
   // os_bzero(confSTA->ssid); <-- if I use this one, then wifi_station_set_config() triggers wdt reset!
   os_bzero(confSTA->ssid, sizeof(confSTA->ssid)); // this one is working
   if (os_strlen(_userSettings->wifiSsid) > 0)
      os_sprintf(confSTA->ssid, "%s", _userSettings->wifiSsid);
      
   wifi_station_set_config(confSTA); // this function fails if os_bzero() has no length specified as a second argument
   os_free(confSTA);
      


Is there any rule of thumb when os_bzero() is safe to use or is in this case bug of wifi_station_set_config()?

Rdds,
Frenk

User avatar
pratik
Posts: 467
Joined: Wed Jun 29, 2016 7:17 pm
Location: India
Contact:

Re: os_bzero() detecting correct length issue

Postby pratik » Thu Sep 08, 2016 12:15 pm

Hello Frenk,

Being specific to os_bzero() or the standard GCC bzero(), it is not a very popular function. Has been marked as legacy by the current GCC standards and is not recommended. Also note that the function sets the initial n bytes of an array to '0' or NULL, when you call the function as follows: os_bzero (str, n);

Always specify the length n!
And if possible, please switch to os_memset. It will work much better and will always work with future SDK versions. :)
Regards,
Pratik Panda
Website: http://www.PratikPanda.com

Custom firmware, Knowledge base and freelancing (ESP8266/ESP32):
http://www.iot-bits.com

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: os_bzero() detecting correct length issue

Postby eriksl » Mon Sep 12, 2016 9:40 pm

I am curious as of why the TS thinks bzero (or os_bzero) can be called with only one argument? See man bzero, it needs both the pointer and the length. It could very well be that bzero calls memset or the other way around, there is no real difference in semantics.

The REAL issue here is, like often, that correct prototypes of SDK functions are simply missing. If the prototype had been there, the TS would have had an error from the compiler and would have know what was the issue.

Proper C language level support from Espressif has always been very lame. I'd really like a better job on this:
- missing lots of prototypes
- use of nonstandard int types (uint32) vs. standard types (uint32_t, stdint.h).
- lots of improper use of #define where an inline function or an enum would be the correct choice

FrenkR
Posts: 42
Joined: Thu Dec 04, 2014 9:25 am

Re: os_bzero() detecting correct length issue

Postby FrenkR » Wed Sep 14, 2016 5:42 pm

thank you for a kind and clear explanation.
Rgds,
Frenk

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: os_bzero() detecting correct length issue

Postby eriksl » Mon Oct 10, 2016 9:51 pm

I think the issue you experienced was that you didn't notice the link between os_bzero() (Espressif function) and bzero() (standard libc function), which has the same semantics.

Who is online

Users browsing this forum: No registered users and 10 guests