Ignore:
Timestamp:
2018-11-09T22:03:24Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba9a150
Parents:
b389f95
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-08 01:26:04)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-09 22:03:24)
Message:

Remove nfmalloc()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    rb389f95 r4f3aa76  
    219219        const char *hint;
    220220        const char *help;
    221         char *output = nfmalloc(MAX_CMDLINE);
    222221        size_t hints_to_show = MAX_TAB_HINTS - 1;
    223222        size_t total_hints_shown = 0;
    224223        bool continue_showing_hints = true;
     224
     225        char *output = malloc(MAX_CMDLINE);
     226        if (!output) {
     227                // TODO: fix the function so that it does not need allocation
     228                printf("Can't complete command, out of memory.\n");
     229                return 0;
     230        }
    225231
    226232        output[0] = 0;
     
    325331}
    326332
    327 NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev)
     333NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev,
     334    char *tmp)
    328335{
    329336        printf("%s> ", prompt);
     
    332339        wchar_t *current = history[history_pos];
    333340        current[0] = 0;
    334         char *tmp = nfmalloc(STR_BOUNDS(MAX_CMDLINE));
    335341
    336342        while (true) {
     
    534540        }
    535541
    536         free(tmp);
    537542        return current;
    538543}
     
    809814                printf("Type \"exit\" to leave the console.\n");
    810815
    811         char *cmdline = nfmalloc(STR_BOUNDS(MAX_CMDLINE));
     816        char *buffer = malloc(STR_BOUNDS(MAX_CMDLINE));
     817        char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE));
     818        if (!buffer || !cmdline) {
     819                // TODO: fix the function so that it does not need allocations
     820                printf("Can't start console, out of memory.\n");
     821                free(buffer);
     822                free(cmdline);
     823                return;
     824        }
     825
    812826        while (true) {
    813                 wchar_t *tmp = clever_readline((char *) prompt, stdin);
     827                wchar_t *tmp = clever_readline((char *) prompt, stdin, buffer);
    814828                size_t len = wstr_length(tmp);
    815829                if (!len)
     
    827841                (void) cmd_info->func(cmd_info->argv);
    828842        }
     843        free(buffer);
    829844        free(cmdline);
    830845}
Note: See TracChangeset for help on using the changeset viewer.