From c39639045c1f1d7ee0ce0396f0010d048ce7d365 Mon Sep 17 00:00:00 2001 From: "DrZiplok@gmail.com" Date: Mon, 1 Nov 2010 03:40:54 +0000 Subject: [PATCH] Default un-supplied command arguments to the empty string and zero rather than leaving them potentially un-initialised. This makes it safe for commands to compare argument strings without adding the expense of checking argc first. git-svn-id: https://arducopter.googlecode.com/svn/trunk@760 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/AP_Common/menu.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/AP_Common/menu.cpp b/libraries/AP_Common/menu.cpp index 58e129d03e..76d4e20247 100644 --- a/libraries/AP_Common/menu.cpp +++ b/libraries/AP_Common/menu.cpp @@ -85,6 +85,15 @@ Menu::run(void) _argv[argc].f = atof(_argv[argc].str); // calls strtod, > 700B ! argc++; } + + // populate arguments that have not been specified with "" and 0 + // this is safer than NULL in the case where commands may look + // without testing argc + while (argc <= MENU_ARGS_MAX) { + _argv[argc].str = ""; + _argv[argc].i = 0; + _argv[argc].f = 0; + } // look for a command matching the first word (note that it may be empty) for (i = 0; i < _entries; i++) {