esp_iot_framework  v0.1.0-alpha
© 2026 AmakeSasha, distributed under a license Apache-2.0

Helper utility functions. More...

Functions

static bool eif_strempty (const char *const str)
 Checks if a string is empty. More...
 
static size_t eif_strnlen (const char *const str, size_t max_allowed)
 Computes the length of string. More...
 

Detailed Description

This module contains inline helper utilities designed for secure and defensive manipulation of strings, preventing common buffer overflows and null-pointer dereferences.

Function Documentation

◆ eif_strempty()

static bool eif_strempty ( const char *const  str)
inlinestatic

Evaluates the provided string to determine if it is either a NULL pointer or points directly to a null-terminator (\0).

Parameters
strPointer to the string. Can be NULL.
Returns
  • true: The string pointer is NULL or the string is empty ("").
  • false: The string is valid and contains at least one character.

Example of use:

#include <esp_log.h>
#include <esp_iot_framework_core_ext.h>
#define TAG "STR_UTIL"
void validate_json_payload(const char * const payload) {
const bool is_empty = eif_strempty(payload);
if (is_empty == true) {
ESP_LOGE(TAG, "Payload is completely empty or NULL.");
} else {
ESP_LOGI(TAG, "Payload validation passed.");
}
}
static bool eif_strempty(const char *const str)
Checks if a string is empty.
Definition: esp_iot_framework_core_ext.h:148

◆ eif_strnlen()

static size_t eif_strnlen ( const char *const  str,
size_t  max_allowed 
)
inlinestatic

Calculates the length of the string str, up to a maximum allowed bound specified by max_allowed.

Parameters
strConstant pointer to the constant string to measure.
max_allowedMaximum number of characters to examine, excluding the null-terminator.
Returns
  • The number of characters in str if a null-terminator is found within the boundary. If str is NULL, returns 0U. If no null-terminator is found within the limit, returns the internal bounded limit.

Example of use:

#include <esp_log.h>
#include <esp_iot_framework_core_ext.h>
#define TAG "STR_UTIL"
#define MAX_BUFFER_SIZE 64U
void check_string_bounds(const char * const user_input) {
const size_t calculated_len = eif_strnlen(user_input, MAX_BUFFER_SIZE);
if (calculated_len > MAX_BUFFER_SIZE) {
ESP_LOGE(TAG, "Input string exceeds maximum allowed limit of %u.", MAX_BUFFER_SIZE);
} else {
ESP_LOGI(TAG, "String length is safe: %zu bytes.", calculated_len);
}
}
static size_t eif_strnlen(const char *const str, size_t max_allowed)
Computes the length of string.
Definition: esp_iot_framework_core_ext.h:186