On Mon, Oct 24, 2011 at 8:25 PM, Zdenek Styblik
<[email protected]> wrote:
[...]
Ok, thanks to Andy's comments, here goes version 2.
~~~ 'lib/helper.c' ~~~
#include <limits.h>
[...]
/* Desc: Convert array of chars into uint8_t and check for overflows
* @str: array of chars to parse from
* @uchr_ptr: pointer to address where uint8_t will be stored
*/
int str2uchar(char *str, uint8_t *uchr_ptr)
{
uint32_t arg_long = 0;
char *end_ptr = 0;
if (!str || !uchr_ptr || sizeof(str) <= 0) {
/* Some of parameters to the function are missing or
are invalid */
return 1;
}
errno = 0;
arg_long = strtoul(str, &end_ptr, 0);
if (*end_ptr != '\0' || errno != 0 || arg_long < 0) {
/* Invalid input given by user/overflow occurred */
return 2;
}
if (arg_long > UCHAR_MAX || arg_long == LONG_MIN || arg_long ==
LONG_MAX) {
/* Given argument is too big to fit uint8_t */
return 3;
}
*uchr_ptr = (uint8_t) arg_long;
return 0;
}
~~~ 'lib/helper.c' ~~~
Zdenek
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Ipmitool-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel