A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/llvm/llvm-project/commit/87c016078ad72c46505461e4ff8bfa04819fe7ba below:

[libc] add atof, strtof and strtod · llvm/llvm-project@87c0160 · GitHub

File tree Expand file treeCollapse file tree 24 files changed

+2301

-0

lines changed

Filter options

Expand file treeCollapse file tree 24 files changed

+2301

-0

lines changed Original file line number Diff line number Diff line change

@@ -56,6 +56,7 @@ set(TARGET_LIBC_ENTRYPOINTS

56 56

# stdlib.h entrypoints

57 57

libc.src.stdlib.abs

58 58

libc.src.stdlib.atoi

59 +

libc.src.stdlib.atof

59 60

libc.src.stdlib.atol

60 61

libc.src.stdlib.atoll

61 62

libc.src.stdlib.bsearch

@@ -65,6 +66,8 @@ set(TARGET_LIBC_ENTRYPOINTS

65 66

libc.src.stdlib.llabs

66 67

libc.src.stdlib.lldiv

67 68

libc.src.stdlib.qsort

69 +

libc.src.stdlib.strtod

70 +

libc.src.stdlib.strtof

68 71

libc.src.stdlib.strtol

69 72

libc.src.stdlib.strtoll

70 73

libc.src.stdlib.strtoul

Original file line number Diff line number Diff line change

@@ -6,3 +6,13 @@ add_libc_fuzzer(

6 6

libc.src.stdlib.qsort

7 7

)

8 8 9 +

add_libc_fuzzer(

10 +

atof_fuzz

11 +

SRCS

12 +

atof_fuzz.cpp

13 +

HDRS

14 +

StringParserOutputDiff.h

15 +

DEPENDS

16 +

libc.src.stdlib.atof

17 +

)

18 + Original file line number Diff line number Diff line change

@@ -0,0 +1,35 @@

1 +

//===-- Template to diff single-input-single-output functions ---*- C++ -*-===//

2 +

//

3 +

// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

4 +

// See https://llvm.org/LICENSE.txt for license information.

5 +

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

6 +

//

7 +

//===----------------------------------------------------------------------===//

8 + 9 +

#ifndef LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H

10 +

#define LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H

11 + 12 +

#include "fuzzing/math/Compare.h"

13 + 14 +

#include <stddef.h>

15 +

#include <stdint.h>

16 + 17 +

template <typename T> using StringInputSingleOutputFunc = T (*)(const char *);

18 + 19 +

template <typename T>

20 +

void StringParserOutputDiff(StringInputSingleOutputFunc<T> func1,

21 +

StringInputSingleOutputFunc<T> func2,

22 +

const uint8_t *data, size_t size) {

23 +

if (size < sizeof(T))

24 +

return;

25 + 26 +

const char *x = reinterpret_cast<const char *>(data);

27 + 28 +

T result1 = func1(x);

29 +

T result2 = func2(x);

30 + 31 +

if (!ValuesEqual(result1, result2))

32 +

__builtin_trap();

33 +

}

34 + 35 +

#endif // LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H

Original file line number Diff line number Diff line change

@@ -0,0 +1,32 @@

1 +

//===-- atof_fuzz.cpp -----------------------------------------------------===//

2 +

//

3 +

// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

4 +

// See https://llvm.org/LICENSE.txt for license information.

5 +

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

6 +

//

7 +

//===----------------------------------------------------------------------===//

8 +

///

9 +

/// Fuzzing test for llvm-libc atof implementation.

10 +

///

11 +

//===----------------------------------------------------------------------===//

12 +

#include "src/stdlib/atof.h"

13 +

#include <stddef.h>

14 +

#include <stdint.h>

15 +

#include <stdlib.h>

16 + 17 +

#include "fuzzing/stdlib/StringParserOutputDiff.h"

18 + 19 +

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

20 +

uint8_t *container = new uint8_t[size + 1];

21 +

if (!container)

22 +

__builtin_trap();

23 +

size_t i;

24 + 25 +

for (i = 0; i < size; ++i)

26 +

container[i] = data[i];

27 +

container[size] = '\0'; // Add null terminator to container.

28 + 29 +

StringParserOutputDiff<double>(&__llvm_libc::atof, &::atof, container, size);

30 +

delete[] container;

31 +

return 0;

32 +

}

Original file line number Diff line number Diff line change

@@ -495,6 +495,7 @@ def StdC : StandardSpec<"stdc"> {

495 495

FunctionSpec<"labs", RetValSpec<LongType>, [ArgSpec<LongType>]>,

496 496

FunctionSpec<"llabs", RetValSpec<LongLongType>, [ArgSpec<LongLongType>]>,

497 497 498 +

FunctionSpec<"atof", RetValSpec<DoubleType>, [ArgSpec<ConstCharRestrictedPtr>]>,

498 499

FunctionSpec<"atoi", RetValSpec<IntType>, [ArgSpec<ConstCharPtr>]>,

499 500

FunctionSpec<"atol", RetValSpec<LongType>, [ArgSpec<ConstCharPtr>]>,

500 501

FunctionSpec<"atoll", RetValSpec<LongLongType>, [ArgSpec<ConstCharPtr>]>,

@@ -505,6 +506,8 @@ def StdC : StandardSpec<"stdc"> {

505 506 506 507

FunctionSpec<"qsort", RetValSpec<VoidType>, [ArgSpec<VoidPtr>, ArgSpec<SizeTType>, ArgSpec<SizeTType>, ArgSpec<QSortCompareT>]>,

507 508 509 +

FunctionSpec<"strtod", RetValSpec<DoubleType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>]>,

510 +

FunctionSpec<"strtof", RetValSpec<FloatType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>]>,

508 511

FunctionSpec<"strtol", RetValSpec<LongType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>, ArgSpec<IntType>]>,

509 512

FunctionSpec<"strtoll", RetValSpec<LongLongType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>, ArgSpec<IntType>]>,

510 513

FunctionSpec<"strtoul", RetValSpec<UnsignedLongType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>, ArgSpec<IntType>]>,

Original file line number Diff line number Diff line change

@@ -23,12 +23,14 @@ add_header_library(

23 23

str_conv_utils

24 24

HDRS

25 25

str_conv_utils.h

26 +

str_to_float.h

26 27

DEPENDS

27 28

.ctype_utils

28 29

.high_precision_decimal

29 30

libc.include.errno

30 31

libc.src.errno.__errno_location

31 32

libc.utils.CPP.standalone_cpp

33 +

libc.src.__support.FPUtil.fputil

32 34

)

33 35 34 36

add_header_library(

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4