mirror of
https://xff.cz/git/u-boot/
synced 2025-09-29 22:41:17 +02:00
lib: errno: check for unsupported error number
If errno_str() is called with an unsupported error number, do not return a random pointer but a reasonable text. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
committed by
Tom Rini
parent
80e7e7c2ab
commit
02e8a8241b
@@ -136,6 +136,8 @@ static const char * const errno_message[] = {
|
|||||||
ERRNO_MSG(EDQUOT, "Quota exceeded"),
|
ERRNO_MSG(EDQUOT, "Quota exceeded"),
|
||||||
ERRNO_MSG(ENOMEDIUM, "No medium found"),
|
ERRNO_MSG(ENOMEDIUM, "No medium found"),
|
||||||
ERRNO_MSG(EMEDIUMTYPE, "Wrong medium type"),
|
ERRNO_MSG(EMEDIUMTYPE, "Wrong medium type"),
|
||||||
|
/* Message for unsupported error numbers */
|
||||||
|
ERRNO_MSG(0, "Unknown error"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *errno_str(int errno)
|
const char *errno_str(int errno)
|
||||||
@@ -143,5 +145,9 @@ const char *errno_str(int errno)
|
|||||||
if (errno >= 0)
|
if (errno >= 0)
|
||||||
return errno_message[0];
|
return errno_message[0];
|
||||||
|
|
||||||
return errno_message[abs(errno)];
|
errno = -errno;
|
||||||
|
if (errno >= ARRAY_SIZE(errno_message))
|
||||||
|
errno = ARRAY_SIZE(errno_message) - 1;
|
||||||
|
|
||||||
|
return errno_message[errno];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user