a5bd9f6
From d2ccb3209c62de4292107df4207c02ee59dc11a9 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Mon, 2 Jul 2012 11:19:22 +0200
f74b50e
Subject: [PATCH 004/482] 	* include/grub/list.h
a5bd9f6
 (FOR_LIST_ELEMENTS_SAFE): New macro. 	* include/grub/command.h
a5bd9f6
 (FOR_COMMANDS_SAFE): Likewise. 	* grub-core/commands/help.c
a5bd9f6
 (grub_cmd_help): Use FOR_COMMANDS_SAFE.
a5bd9f6
a5bd9f6
---
a5bd9f6
 grub-core/commands/help.c | 5 +++--
a5bd9f6
 include/grub/command.h    | 1 +
a5bd9f6
 include/grub/list.h       | 1 +
a5bd9f6
 3 files changed, 5 insertions(+), 2 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/grub-core/commands/help.c b/grub-core/commands/help.c
a5bd9f6
index d64c289..f0be89b 100644
a5bd9f6
--- a/grub-core/commands/help.c
a5bd9f6
+++ b/grub-core/commands/help.c
a5bd9f6
@@ -99,12 +99,13 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc,
a5bd9f6
   else
a5bd9f6
     {
a5bd9f6
       int i;
a5bd9f6
-      grub_command_t cmd_iter, cmd;
a5bd9f6
+      grub_command_t cmd_iter, cmd, cmd_next;
a5bd9f6
 
a5bd9f6
       for (i = 0; i < argc; i++)
a5bd9f6
 	{
a5bd9f6
 	  currarg = args[i];
a5bd9f6
-	  FOR_COMMANDS(cmd_iter)
a5bd9f6
+
a5bd9f6
+	  FOR_COMMANDS_SAFE (cmd_iter, cmd_next)
a5bd9f6
 	  {
a5bd9f6
 	    if (!(cmd_iter->prio & GRUB_COMMAND_FLAG_ACTIVE))
a5bd9f6
 	      continue;
a5bd9f6
diff --git a/include/grub/command.h b/include/grub/command.h
a5bd9f6
index 6d43499..8705a63 100644
a5bd9f6
--- a/include/grub/command.h
a5bd9f6
+++ b/include/grub/command.h
a5bd9f6
@@ -121,6 +121,7 @@ grub_command_execute (const char *name, int argc, char **argv)
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 #define FOR_COMMANDS(var) FOR_LIST_ELEMENTS((var), grub_command_list)
a5bd9f6
+#define FOR_COMMANDS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), grub_command_list)
a5bd9f6
 
a5bd9f6
 void grub_register_core_commands (void);
a5bd9f6
 
a5bd9f6
diff --git a/include/grub/list.h b/include/grub/list.h
a5bd9f6
index cadb2d9..6f6dec0 100644
a5bd9f6
--- a/include/grub/list.h
a5bd9f6
+++ b/include/grub/list.h
a5bd9f6
@@ -35,6 +35,7 @@ void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
a5bd9f6
 void EXPORT_FUNC(grub_list_remove) (grub_list_t item);
a5bd9f6
 
a5bd9f6
 #define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
a5bd9f6
+#define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), (nxt) = (var)->next)
a5bd9f6
 
a5bd9f6
 static inline void *
a5bd9f6
 grub_bad_type_cast_real (int line, const char *file)
a5bd9f6
-- 
31004e6
1.8.2.1
a5bd9f6