Skip to content

Commit

Permalink
pre-commit: Apply clang-format change globally
Browse files Browse the repository at this point in the history
clang-format automatically reformats the entire source code based on
.clang-format configuration.

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim authored and Bojun-Seo committed Mar 13, 2023
1 parent 993d3dd commit 1f7fa96
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 239 deletions.
8 changes: 4 additions & 4 deletions samples/factorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"

__attribute__((noinline))
int fac(int n)
__attribute__((noinline)) int fac(int n)
{
malloc(n);
if ( n == 0 ) {
if (n == 0) {
calloc(10, 1);
malloc(10);
return 1;
} else {
}
else {
return n * fac(n - 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions samples/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ int main(void)
{
int *p;

p = (int*)malloc(4);
p = (int *)malloc(4);
free(p);

p = (int*)calloc(4, 10);
p = (int *)calloc(4, 10);

p = (int*)realloc(p, 1000000);
p = (int *)realloc(p, 1000000);
free(p);

return 0;
Expand Down
6 changes: 3 additions & 3 deletions samples/sample_leak.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ int main(void)
{
int *p;

p = (int*)malloc(4);
p = (int *)malloc(4);
//free(p);

p = (int*)calloc(4, 10);
p = (int *)calloc(4, 10);

p = (int*)realloc(p, 1000000);
p = (int *)realloc(p, 1000000);
free(p);

return 0;
Expand Down
22 changes: 11 additions & 11 deletions src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
#ifndef HEAPTRACE_COMPILER_H
#define HEAPTRACE_COMPILER_H

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

#define __constructor __attribute__((constructor))
#define __destructor __attribute__((destructor))
#define __constructor __attribute__((constructor))
#define __destructor __attribute__((destructor))

#define __weak __attribute__((weak))
#define __visible_default __attribute__((visibility("default")))
#define __alias(func) __attribute__((alias(#func)))
#define __maybe_unused __attribute__((unused))
#define __used __attribute__((used))
#define __noreturn __attribute__((noreturn))
#define __align(n) __attribute__((aligned(n)))
#define __weak __attribute__((weak))
#define __visible_default __attribute__((visibility("default")))
#define __alias(func) __attribute__((alias(#func)))
#define __maybe_unused __attribute__((unused))
#define __used __attribute__((used))
#define __noreturn __attribute__((noreturn))
#define __align(n) __attribute__((aligned(n)))

#endif /* HEAPTRACE_COMPILER_H */
8 changes: 4 additions & 4 deletions src/heaptrace.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Copyright (c) 2022 LG Electronics Inc. */
/* SPDX-License-Identifier: GPL-2.0 */
#include <argp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <argp.h>

#include <string>
#include <sstream>
#include <string>

#include "heaptrace.h"

Expand Down Expand Up @@ -39,11 +39,11 @@ static struct argp_option heaptrace_options[] = {

static error_t parse_option(int key, char *arg, struct argp_state *state)
{
struct opts *opts = (struct opts*)state->input;
struct opts *opts = (struct opts *)state->input;

switch (key) {
case 'h':
argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
break;

case OPT_top:
Expand Down
26 changes: 13 additions & 13 deletions src/heaptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

extern FILE *outfp;

#define TERM_COLOR_NORMAL ""
#define TERM_COLOR_RESET "\033[0m"
#define TERM_COLOR_BOLD "\033[1m"
#define TERM_COLOR_RED "\033[91m" /* bright red */
#define TERM_COLOR_GREEN "\033[32m"
#define TERM_COLOR_YELLOW "\033[33m"
#define TERM_COLOR_BLUE "\033[94m" /* bright blue */
#define TERM_COLOR_MAGENTA "\033[35m"
#define TERM_COLOR_CYAN "\033[36m"
#define TERM_COLOR_GRAY "\033[90m" /* bright black */
#define TERM_COLOR_NORMAL ""
#define TERM_COLOR_RESET "\033[0m"
#define TERM_COLOR_BOLD "\033[1m"
#define TERM_COLOR_RED "\033[91m" /* bright red */
#define TERM_COLOR_GREEN "\033[32m"
#define TERM_COLOR_YELLOW "\033[33m"
#define TERM_COLOR_BLUE "\033[94m" /* bright blue */
#define TERM_COLOR_MAGENTA "\033[35m"
#define TERM_COLOR_CYAN "\033[36m"
#define TERM_COLOR_GRAY "\033[90m" /* bright black */

#ifdef DEBUG
#define pr_dbg(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
#define pr_dbg(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#else
#define pr_dbg(fmt, ...)
#endif

#define pr_out(fmt, ...) fprintf(outfp, fmt, ## __VA_ARGS__)
#define pr_out(fmt, ...) fprintf(outfp, fmt, ##__VA_ARGS__)

#define pr_red(fmt, ...) fprintf(stdout, TERM_COLOR_RED fmt TERM_COLOR_RESET, ## __VA_ARGS__)
#define pr_red(fmt, ...) fprintf(stdout, TERM_COLOR_RED fmt TERM_COLOR_RESET, ##__VA_ARGS__)

struct thread_flags_t {
// to protect unexpected recursive malloc calls
Expand Down
Loading

0 comments on commit 1f7fa96

Please sign in to comment.