summaryrefslogtreecommitdiff
path: root/firmware/common/file_internal.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2014-09-02 15:57:18 -0400
committerMichael Sevakis <jethead71@rockbox.org>2014-09-02 15:57:18 -0400
commit0a66545487cf2457c6f483c288d02fc23ec705bb (patch)
treefa73ec372a84c4b2ee0449c8fa0dac5691809481 /firmware/common/file_internal.c
parent802e0110db79473861b2859a5c1c7cc3764d9e5f (diff)
downloadrockbox-0a66545487cf2457c6f483c288d02fc23ec705bb.tar.gz
rockbox-0a66545487cf2457c6f483c288d02fc23ec705bb.zip
Clean up a bit and get switch statement out of loop in walk_path()
It's nicer to look at and it obfuscated a bug where it should have exited the loop instead of the case (you probably wouldn't observe the effect very often). Change-Id: I33f3c72c8bb7e11b9d418f66cf84efc3082a37b4
Diffstat (limited to 'firmware/common/file_internal.c')
-rw-r--r--firmware/common/file_internal.c69
1 files changed, 31 insertions, 38 deletions
diff --git a/firmware/common/file_internal.c b/firmware/common/file_internal.c
index b66aafd61e..58cb8830d1 100644
--- a/firmware/common/file_internal.c
+++ b/firmware/common/file_internal.c
@@ -498,51 +498,44 @@ walk_path(struct pathwalk *walkp, struct pathwalk_component *compp,
498 if (!(compp->attr & ATTR_DIRECTORY)) 498 if (!(compp->attr & ATTR_DIRECTORY))
499 return -ENOTDIR; 499 return -ENOTDIR;
500 500
501 switch (len) 501 if (len >= MAX_NAME)
502 return -ENAMETOOLONG;
503
504 /* check for "." and ".." */
505 if (name[0] == '.')
502 { 506 {
503 case 1: 507 if (len == 1)
504 case 2: 508 continue; /* is "." */
505 /* check for "." and ".." */ 509
506 if (name[0] == '.') 510 if (len == 2 && name[1] == '.')
507 { 511 {
508 if (len == 1) 512 /* is ".." */
509 break; /* is "." */ 513 struct pathwalk_component *parentp = compp->nextp;
510 514 if (!parentp)
511 if (name[1] == '.') 515 return WALK_RC_CONT_AT_ROOT;
512 { 516
513 /* is ".." */ 517 compp->nextp = freep;
514 struct pathwalk_component *parentp = compp->nextp; 518 freep = compp;
515 if (!parentp) 519 compp = parentp;
516 return WALK_RC_CONT_AT_ROOT; 520 continue;
517
518 compp->nextp = freep;
519 freep = compp;
520 compp = parentp;
521 break;
522 }
523 } 521 }
522 }
524 523
525 /* fallthrough */ 524 struct pathwalk_component *newp = freep;
526 default: 525 if (!newp)
527 if (len >= MAX_NAME) 526 newp = pathwalk_comp_alloc(compp);
528 return -ENAMETOOLONG; 527 else
529 528 freep = freep->nextp;
530 struct pathwalk_component *newp = freep;
531 if (!newp)
532 newp = pathwalk_comp_alloc(compp);
533 else
534 freep = freep->nextp;
535 529
536 newp->nextp = compp; 530 newp->nextp = compp;
537 compp = newp; 531 compp = newp;
538 532
539 compp->name = name; 533 compp->name = name;
540 compp->length = len; 534 compp->length = len;
541 535
542 rc = open_path_component(walkp, compp, stream); 536 rc = open_path_component(walkp, compp, stream);
543 if (rc < 0) 537 if (rc < 0)
544 break; 538 break; /* return info below */
545 }
546 } 539 }
547 540
548 return walk_open_info(walkp, compp, rc, stream); 541 return walk_open_info(walkp, compp, rc, stream);