Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ Table of Defects
* - `exiv2 <https://github.com/Exiv2/exiv2.git/>`_
- 20
- Exiv2 is a C++ library and a command-line utility to read, write, delete and modify Exif, IPTC, XMP and ICC image metadata
* - `gravity <https://github.com/marcobambini/gravity/>`_
- 3
- Gravity is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependencies (except for stdlib).
* - `jerryscript <https://github.com/jerryscript-project/jerryscript.git/>`_
- 11
- JerryScript is a lightweight JavaScript engine for resource-constrained devices such as microcontrollers.
Expand Down Expand Up @@ -237,7 +240,7 @@ Table of Defects
- 5
- Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.
* - SUM
- 215
- 218
- Sum of all defects


Expand Down
3 changes: 3 additions & 0 deletions bugscpp/taxonomy/gravity/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2021 Suresoft Technologies Inc.
# Licensed under the MIT
FROM hschoe/defects4cpp-ubuntu:gravity
Empty file.
37 changes: 37 additions & 0 deletions bugscpp/taxonomy/gravity/extra/0001/.dpp/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import sys
import shutil
from pathlib import Path


if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python run_test.py [INDEX]")
sys.exit(1)
index = int(sys.argv[1])

root_dir = Path('test/unittest')
disabled_dir = Path('test/unittest/disabled')
all_gravity_files = list(root_dir.rglob('*.gravity'))
all_gravity_files.remove(Path('test/unittest/include_test.gravity'))

sorted_gravity_files = sorted([f for f in all_gravity_files if disabled_dir not in f.parents])

# for i, v in enumerate(sorted_gravity_files):
# print(i+1, v)

unittest_dir = Path('unittest')
unittest_dir.mkdir(parents=True, exist_ok=True)

test_file = sorted_gravity_files[index - 1]
destination = unittest_dir / test_file.name
shutil.copyfile(test_file, destination)
result = subprocess.run(['./gravity', '-t', str(unittest_dir)], capture_output=True, text=True)
ret = 0
if result.returncode != 0:
print(f"Failed test {destination}")
print(result.stdout)
ret = 1

shutil.rmtree(unittest_dir)
exit(ret)
35 changes: 35 additions & 0 deletions bugscpp/taxonomy/gravity/extra/0002/.dpp/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess
import sys
import shutil
from pathlib import Path


if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python run_test.py [INDEX]")
sys.exit(1)
index = int(sys.argv[1])

root_dir = Path('test/unittest')
disabled_dir = Path('test/unittest/disabled')
all_gravity_files = list(root_dir.rglob('*.gravity'))
all_gravity_files.remove(Path('test/unittest/include_test.gravity'))

sorted_gravity_files = sorted([f for f in all_gravity_files if disabled_dir not in f.parents])

unittest_dir = Path('unittest_test')
unittest_dir.mkdir(parents=True, exist_ok=True)

test_file = sorted_gravity_files[index - 1]
destination = unittest_dir / test_file.name
shutil.copyfile(test_file, destination)
result = subprocess.run(['./unittest', str(unittest_dir)], capture_output=True, text=True)
ret = 0
if result.returncode != 0:
print(f"Failed test {destination}")
print(result.stdout)
ret = 1

shutil.rmtree(unittest_dir)
exit(ret)

37 changes: 37 additions & 0 deletions bugscpp/taxonomy/gravity/extra/0003/.dpp/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import sys
import shutil
from pathlib import Path


if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python run_test.py [INDEX]")
sys.exit(1)
index = int(sys.argv[1])

root_dir = Path('test/unittest')
disabled_dir = Path('test/unittest/disabled')
all_gravity_files = list(root_dir.rglob('*.gravity'))
all_gravity_files.remove(Path('test/unittest/include_test.gravity'))

sorted_gravity_files = sorted([f for f in all_gravity_files if disabled_dir not in f.parents])

# for i, v in enumerate(sorted_gravity_files):
# print(i+1, v)

unittest_dir = Path('unittest_test')
unittest_dir.mkdir(parents=True, exist_ok=True)

test_file = sorted_gravity_files[index - 1]
destination = unittest_dir / test_file.name
shutil.copyfile(test_file, destination)
result = subprocess.run(['./unittest', str(unittest_dir)], capture_output=True, text=True)
ret = 0
if result.returncode != 0:
print(f"Failed test {destination}")
print(result.stdout)
ret = 1

shutil.rmtree(unittest_dir)
exit(ret)
102 changes: 102 additions & 0 deletions bugscpp/taxonomy/gravity/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"info": {
"url": "https://github.com/marcobambini/gravity",
"short-desc": "Gravity is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependencies (except for stdlib).",
"vcs": "git"
},
"common": {
"build": {
"commands": [
{
"type": "docker",
"lines": [
"make clean",
"make -j @DPP_PARALLEL_BUILD@"
]
}
]
},
"build-coverage": {
"commands": [
{
"type": "docker",
"lines": [
"make clean",
"make CFLAGS=\"-Isrc/compiler/ -Isrc/runtime/ -Isrc/shared/ -Isrc/utils/ -Isrc/optionals/ -std=gnu99 -fgnu89-inline -fPIC -DBUILD_GRAVITY_API -g -O0 --coverage\" -j @DPP_PARALLEL_BUILD@"
]
}
]
},
"test-type": "ctest",
"test": {
"commands": [
{
"type": "docker",
"lines": [
"bash -c \"python .dpp/run_test.py $(cat DPP_TEST_INDEX)\""
]
}
]
},
"test-coverage": {
"commands": [
{
"type": "docker",
"lines": [
"bash -c \"python .dpp/run_test.py $(cat DPP_TEST_INDEX)\""
]
}
]
},
"gcov": {
"exclude": [],
"commands": [
{
"type": "docker",
"lines": [
"mkdir gcov",
"bash -c 'find ./src -type f -name \"*.o\" -exec gcov @DPP_ADDITIONAL_GCOV_OPTIONS@ --preserve-paths {} \\;'",
"bash -c 'mv *.gcov ./gcov'",
"bash -c 'find ./gcov -type f -name \"*.gcda\" -delete'"
]
}
]
}
},
"defects": [
{
"id": 1,
"hash": "63fa9bf0393dbbdfa1d4cb1f532df6e099f7c0b7",
"num_cases": 290,
"case": [93],
"tags": [
"single-line",
"modified"
],
"description": "Fixed a possible GC issue (unit test added)"
},
{
"id": 2,
"hash": "8cf6379645f458384fc44b627662de5345696072",
"num_cases": 229,
"case": [158],
"tags": [
"multi-lines",
"memory-error"
],
"description": "Fixed a crash that can occurs when an insane amount of memory is requested. Introduced a new MAX_MEMORY_BLOCK define."
},
{
"id": 3,
"hash": "9231f9e1a7d52712a06390ece55a30fe0d60677a",
"num_cases": 241,
"case": [184],
"tags": [
"multi-line",
"modified",
"added"
],
"description": "Fixed a rare issue that can occurs in register allocation."
}
]
}
27 changes: 27 additions & 0 deletions bugscpp/taxonomy/gravity/patch/0001-buggy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From ea4f453c4141ac4787a31a9ebd2f3dee0e70a407 Mon Sep 17 00:00:00 2001
From: Hansol Choe <hschoe@suresofttech.com>
Date: Wed, 20 Dec 2023 01:58:04 +0000
Subject: [PATCH] buggy

---
src/runtime/gravity_vm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/runtime/gravity_vm.c b/src/runtime/gravity_vm.c
index c80a32a..ce159ed 100644
--- a/src/runtime/gravity_vm.c
+++ b/src/runtime/gravity_vm.c
@@ -1451,9 +1451,8 @@ static bool gravity_vm_exec (gravity_vm *vm) {
if (op != MOVE) RUNTIME_ERROR("Wrong OPCODE in CLOSURE statement");
closure->upvalue[i] = (p2) ? gravity_capture_upvalue (vm, fiber, &stackstart[p1]) : frame->closure->upvalue[p1];
}
-
- SETVALUE(r1, VALUE_FROM_OBJECT(closure));
gravity_gc_setenabled(vm, true);
+ SETVALUE(r1, VALUE_FROM_OBJECT(closure));
DISPATCH();
}

--
2.25.1

111 changes: 111 additions & 0 deletions bugscpp/taxonomy/gravity/patch/0002-buggy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
From 5f98597fa82f2c403055c3be212ad2b66d836c6a Mon Sep 17 00:00:00 2001
From: Hansol Choe <hschoe@suresofttech.com>
Date: Wed, 20 Dec 2023 04:19:16 +0000
Subject: [PATCH] buggy

---
src/runtime/gravity_core.c | 35 ++++++++++-------------------------
src/shared/gravity_value.h | 5 ++---
2 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/src/runtime/gravity_core.c b/src/runtime/gravity_core.c
index ffeee2e..6f569d3 100644
--- a/src/runtime/gravity_core.c
+++ b/src/runtime/gravity_core.c
@@ -932,12 +932,10 @@ static bool list_join (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui

// create a new empty buffer
uint32_t alloc = (uint32_t) (marray_size(list->array) * 64);
- if (alloc > MAX_MEMORY_BLOCK) RETURN_ERROR("Maximum memory block size reached (max %d, requested %d).", MAX_MEMORY_BLOCK, alloc);
-
uint32_t len = 0;
uint32_t seplen = (sep) ? VALUE_AS_STRING(GET_VALUE(1))->len : 0;
- char *_buffer = mem_alloc(alloc);
- if (!_buffer) RETURN_ERROR("Not enought memory to allocate a buffer for the join operation.");
+ char *buffer = mem_alloc(alloc);
+ assert(buffer);

register gravity_int_t n = marray_size(list->array);
register gravity_int_t i = 0;
@@ -946,47 +944,34 @@ static bool list_join (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
while (i < n) {
gravity_value_t value = convert_value2string(vm, marray_get(list->array, i));
if (VALUE_ISA_ERROR(value)) {
- mem_free(_buffer);
+ mem_free(buffer);
RETURN_VALUE(value, rindex);
}

- // compute string to appen
const char *s2 = VALUE_AS_STRING(value)->s;
uint32_t req = VALUE_AS_STRING(value)->len;
- uint32_t free_mem = alloc - len;
+ uint32_t free = alloc - len;

// check if buffer needs to be reallocated
- if (free_mem < req + seplen) {
- uint64_t to_alloc = alloc + (req + seplen) * 2 + 4096;
-
- // sanity check
- if (to_alloc > MAX_MEMORY_BLOCK) {
- mem_free(_buffer);
- RETURN_ERROR("Maximum memory block size reached (max %d, requested %lld).", MAX_MEMORY_BLOCK, to_alloc);
- }
-
- _buffer = mem_realloc(_buffer, (uint32_t)to_alloc);
- if (!_buffer) {
- mem_free(_buffer);
- RETURN_ERROR("Not enought memory to re-allocate a buffer for the join operation.");
- }
- alloc = (uint32_t)to_alloc;
+ if (free < req + seplen) {
+ buffer = mem_realloc(buffer, (alloc * 2) + req + seplen);
+ alloc += alloc + req + seplen;
}

// copy s2 to into buffer
- memcpy(_buffer+len, s2, req);
+ memcpy(buffer+len, s2, req);
len += req;

// check for separator string
if (i+1 < n && seplen) {
- memcpy(_buffer+len, sep, seplen);
+ memcpy(buffer+len, sep, seplen);
len += seplen;
}

++i;
}

- gravity_string_t *result = gravity_string_new(vm, _buffer, len, alloc);
+ gravity_string_t *result = gravity_string_new(vm, buffer, len, alloc);
RETURN_VALUE(VALUE_FROM_OBJECT(result), rindex);
}

diff --git a/src/shared/gravity_value.h b/src/shared/gravity_value.h
index 57f97c0..26e6167 100644
--- a/src/shared/gravity_value.h
+++ b/src/shared/gravity_value.h
@@ -66,8 +66,8 @@
extern "C" {
#endif

-#define GRAVITY_VERSION "0.2.8" // git tag 0.2.8
-#define GRAVITY_VERSION_NUMBER 0x000208 // git push --tags
+#define GRAVITY_VERSION "0.2.8"
+#define GRAVITY_VERSION_NUMBER 0x000208
#define GRAVITY_BUILD_DATE __DATE__

#define GRAVITY_ENABLE_DOUBLE 1 // if 1 enable gravity_float_t to be a double (instead of a float)
@@ -113,7 +113,6 @@ extern "C" {
#define MAX_IVARS 768 // 2^10 - 2^8
#define MAX_ALLOCATION 4194304 // 1024 * 1024 * 4 (about 4 millions entry)
#define MAX_CCALLS 100 // default maximum number of nested C calls
-#define MAX_MEMORY_BLOCK 157286400 // 150MB

#define DEFAULT_CONTEXT_SIZE 256 // default VM context entries (can grow)
#define DEFAULT_MINSTRING_SIZE 32 // minimum string allocation size
--
2.25.1

Loading