Changeset 713ba400 in mainline for uspace/app/perf/perf.c


Ignore:
Timestamp:
2019-01-01T19:53:07Z (5 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
858469f
Parents:
32236e5
Message:

Refactoring in tester and perf

Use can_cast_size_t_to_int instead of the body of this function.

Also replaced "if" with assert() as the overflow (see diff) can rarely
happen and actually denotes a problem with the test itself (really,
test name longer than MAX_INT is insane).

Notice how the code from kernel was ported to userspace without changes
to the error text that would printed :-).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/perf/perf.c

    r32236e5 r713ba400  
    3535 */
    3636
     37#include <assert.h>
    3738#include <stdio.h>
    3839#include <stddef.h>
     
    4243#include <errno.h>
    4344#include <perf.h>
     45#include <types/casting.h>
    4446#include "perf.h"
    4547#include "benchlist.h"
     
    226228        }
    227229
    228         unsigned int _len = (unsigned int) len;
    229         if ((_len != len) || (((int) _len) < 0)) {
    230                 printf("Command length overflow\n");
    231                 return;
    232         }
     230        assert(can_cast_size_t_to_int(len) && "benchmark name length overflow");
    233231
    234232        for (size_t i = 0; i < benchmark_count; i++)
    235                 printf("%-*s %s\n", _len, benchmarks[i]->name, benchmarks[i]->desc);
    236 
    237         printf("%-*s Run all benchmarks\n", _len, "*");
     233                printf("%-*s %s\n", (int) len, benchmarks[i]->name, benchmarks[i]->desc);
     234
     235        printf("%-*s Run all benchmarks\n", (int) len, "*");
    238236}
    239237
Note: See TracChangeset for help on using the changeset viewer.