Skip to content

Commit

Permalink
convert while-loops into for ones
Browse files Browse the repository at this point in the history
  • Loading branch information
er13 committed Mar 26, 2017
1 parent 734e467 commit 5e3304c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
8 changes: 2 additions & 6 deletions avm_kernel_config/avm_kernel_config_helpers.c
Expand Up @@ -135,14 +135,12 @@ bool isConsistentConfigArea(struct _avm_kernel_config * *configArea, size_t conf
assumeSwapped = (tag <= avm_kernel_config_tags_last ? false : true);

// check other tags
entry = (struct _avm_kernel_config *) arrayStart;
while (entry->config != NULL)
for (entry = (struct _avm_kernel_config *) arrayStart; entry->config != NULL; entry++)
{
tag = entry->tag;
swapEndianess(assumeSwapped, &tag);
// invalid value means, our assumption was wrong
if (tag != 0 && tag > avm_kernel_config_tags_last) return false;
entry++;
}

// now we compute offset in kernel
Expand All @@ -155,15 +153,13 @@ bool isConsistentConfigArea(struct _avm_kernel_config * *configArea, size_t conf
return false;

// check each entry->config pointer, if its value is in range
entry = (struct _avm_kernel_config *) arrayStart;
while (entry->config != NULL)
for (entry = (struct _avm_kernel_config *) arrayStart; entry->config != NULL; entry++)
{
ptrValue = (uint32_t) entry->config;
swapEndianess(assumeSwapped, &ptrValue);

if (ptrValue <= offset) return false; // points before, impossible
if (ptrValue - offset > configSize) return false; // points after
entry++;
}

// we may be sure here, that the endianess was detected successful
Expand Down
7 changes: 2 additions & 5 deletions avm_kernel_config/gen_avm_kernel_config.c
Expand Up @@ -154,16 +154,13 @@ void processModuleMemoryEntry(struct _avm_kernel_config* entry)

struct _avm_kernel_config* findEntry(struct _avm_kernel_config * *configArea, enum _avm_kernel_config_tags tag)
{
struct _avm_kernel_config * entry = *configArea;

if (entry == NULL)
if (*configArea == NULL)
return NULL;

while (entry->config != NULL)
for (struct _avm_kernel_config * entry = *configArea; entry->config != NULL; entry++)
{
if (entry->tag == tag)
return entry;
entry++;
}

return NULL;
Expand Down

0 comments on commit 5e3304c

Please sign in to comment.