diff options
Diffstat (limited to 'apps/tree.c')
-rw-r--r-- | apps/tree.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/apps/tree.c b/apps/tree.c index 5e841e4dae..4d915ca3b8 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -511,17 +511,17 @@ void resume_directory(const char *dir) | |||
511 | 511 | ||
512 | /* Returns the current working directory and also writes cwd to buf if | 512 | /* Returns the current working directory and also writes cwd to buf if |
513 | non-NULL. In case of error, returns NULL. */ | 513 | non-NULL. In case of error, returns NULL. */ |
514 | char *getcwd(char *buf, int size) | 514 | char *getcwd(char *buf, size_t size) |
515 | { | 515 | { |
516 | if (!buf) | 516 | if (!buf) |
517 | return tc.currdir; | 517 | return tc.currdir; |
518 | else if (size > 0) | 518 | else if (size) |
519 | { | 519 | { |
520 | strlcpy(buf, tc.currdir, size); | 520 | if (strlcpy(buf, tc.currdir, size) < size) |
521 | return buf; | 521 | return buf; |
522 | } | 522 | } |
523 | else | 523 | /* size == 0, or truncation in strlcpy */ |
524 | return NULL; | 524 | return NULL; |
525 | } | 525 | } |
526 | 526 | ||
527 | /* Force a reload of the directory next time directory browser is called */ | 527 | /* Force a reload of the directory next time directory browser is called */ |
@@ -530,19 +530,28 @@ void reload_directory(void) | |||
530 | reload_dir = true; | 530 | reload_dir = true; |
531 | } | 531 | } |
532 | 532 | ||
533 | void get_current_file(char* buffer, int buffer_len) | 533 | char* get_current_file(char* buffer, size_t buffer_len) |
534 | { | 534 | { |
535 | #ifdef HAVE_TAGCACHE | 535 | #ifdef HAVE_TAGCACHE |
536 | /* in ID3DB mode it is a bad idea to call this function */ | 536 | /* in ID3DB mode it is a bad idea to call this function */ |
537 | /* (only happens with `follow playlist') */ | 537 | /* (only happens with `follow playlist') */ |
538 | if( *tc.dirfilter == SHOW_ID3DB ) | 538 | if( *tc.dirfilter == SHOW_ID3DB ) |
539 | return; | 539 | return NULL; |
540 | #endif | 540 | #endif |
541 | 541 | ||
542 | struct entry* dc = tc.dircache; | 542 | struct entry* dc = tc.dircache; |
543 | struct entry* e = &dc[tc.selected_item]; | 543 | struct entry* e = &dc[tc.selected_item]; |
544 | snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0), | 544 | if (getcwd(buffer, buffer_len)) |
545 | tc.dirlength ? e->name : ""); | 545 | { |
546 | if (tc.dirlength) | ||
547 | { | ||
548 | strlcat(buffer, "/", buffer_len); | ||
549 | if (strlcat(buffer, e->name, buffer_len) >= buffer_len) | ||
550 | return NULL; | ||
551 | } | ||
552 | return buffer; | ||
553 | } | ||
554 | return NULL; | ||
546 | } | 555 | } |
547 | 556 | ||
548 | /* Allow apps to change our dirfilter directly (required for sub browsers) | 557 | /* Allow apps to change our dirfilter directly (required for sub browsers) |