s3-lib: Use ARRAY_SIZE() to walk the error mapping tables
authorAndrew Bartlett <abartlet@samba.org>
Mon, 30 May 2011 22:44:02 +0000 (08:44 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 31 May 2011 00:57:19 +0000 (02:57 +0200)
This gives a constant termination condition, and may help the compiler.

Andrew Bartlett

source3/lib/errmap_unix.c

index f0ae217222e35ff6538d206da13fffc3172ba7a9..90fd9d68c8364154abfe7dbc06efc6d3fa90c7a9 100644 (file)
@@ -111,7 +111,6 @@ static const struct {
 #ifdef ENOTSUP
         { ENOTSUP, NT_STATUS_NOT_SUPPORTED},
 #endif
-       { 0, NT_STATUS_OK }
 };
 
 /*********************************************************************
@@ -134,10 +133,10 @@ NTSTATUS map_nt_error_from_unix(int unix_error)
        }
 
        /* Look through list */
-       while(unix_nt_errmap[i].unix_error != 0) {
-               if (unix_nt_errmap[i].unix_error == unix_error)
+       for (i=0;i<ARRAY_SIZE(unix_nt_errmap);i++) {
+               if (unix_nt_errmap[i].unix_error == unix_error) {
                        return unix_nt_errmap[i].nt_error;
-               i++;
+               }
        }
 
        /* Default return */
@@ -254,7 +253,6 @@ static const struct {
 #ifdef EXDEV
        {NT_STATUS_NOT_SAME_DEVICE, EXDEV},
 #endif
-       {NT_STATUS(0), 0}
 };
 
 int map_errno_from_nt_status(NTSTATUS status)
@@ -269,7 +267,7 @@ int map_errno_from_nt_status(NTSTATUS status)
                return 0;
        }
 
-       for (i=0;nt_errno_map[i].error;i++) {
+       for (i=0;i<ARRAY_SIZE(nt_errno_map);i++) {
                if (NT_STATUS_V(nt_errno_map[i].status) ==
                            NT_STATUS_V(status)) {
                        return nt_errno_map[i].error;