mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
libc/unistd: getopt: add some NULL pointer checks
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
committed by
Xiang Xiao
parent
bb54ed4227
commit
17bfa18679
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -514,7 +515,7 @@ int getopt_common(int argc, FAR char * const argv[],
|
|||||||
* not think that the first interpretation is standard.
|
* not think that the first interpretation is standard.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
else if (*(go->go_optptr + 1) != '\0')
|
else if (go->go_optptr == NULL || go->go_optptr[1] != '\0')
|
||||||
{
|
{
|
||||||
/* Skip over the unrecognized long option. */
|
/* Skip over the unrecognized long option. */
|
||||||
|
|
||||||
@@ -542,6 +543,8 @@ int getopt_common(int argc, FAR char * const argv[],
|
|||||||
* (which could be another single character command).
|
* (which could be another single character command).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT(go->go_optptr != NULL);
|
||||||
|
|
||||||
go->go_optopt = *go->go_optptr;
|
go->go_optopt = *go->go_optptr;
|
||||||
go->go_optptr = NULL;
|
go->go_optptr = NULL;
|
||||||
go->go_optind++;
|
go->go_optind++;
|
||||||
@@ -570,6 +573,8 @@ int getopt_common(int argc, FAR char * const argv[],
|
|||||||
|
|
||||||
/* Check if the option appears in 'optstring' */
|
/* Check if the option appears in 'optstring' */
|
||||||
|
|
||||||
|
DEBUGASSERT(go->go_optptr != NULL);
|
||||||
|
|
||||||
optchar = strchr(optstring, *go->go_optptr);
|
optchar = strchr(optstring, *go->go_optptr);
|
||||||
if (!optchar)
|
if (!optchar)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user