Skip to content
Snippets Groups Projects
Commit 27233533 authored by Florian Steinkamp's avatar Florian Steinkamp
Browse files

Initialer commit.

parents
No related branches found
No related tags found
No related merge requests found
Makefile 0 → 100644
CXXFLAGS=-std=c++17
default: main
fuzz_main: main.cpp
afl-g++ $(CXXFLAGS) -o fuzz_main main.cpp
fuzz: fuzz_main
rm -rf out
afl-fuzz -i in -o out -- ./fuzz_main
clean:
rm -rf main fuzz_main out
with import (import ./nixpkgs.nix) {};
stdenv.mkDerivation {
name = "fuzzer-example";
src = ./.;
nativeBuildInputs = [ afl ];
installPhase = ''
mkdir -p $out
find . -executable -type f -exec cp {} $out \;
'';
}
fuzz_main 0 → 100755
File added
11+3+2/
11/
main 0 → 100755
File added
main.cpp 0 → 100644
#include <iostream>
#include <optional>
#include <stack>
#include <stdexcept>
#include <climits>
#include <unordered_map>
#include <iterator>
std::stack<int> stack;
int plus(int a, int b) {
return a + b;
}
int minus(int a, int b) {
return b - a;
}
int produkt(int a, int b) {
return a * b;
}
int division(int a, int b) {
if (b == 0) {
throw std::invalid_argument("Division durch 0!");
}
return a / b;
}
std::unordered_map<char, decltype(&plus)> map {
{'+', plus},
{'-', minus},
{'*', produkt},
{'/', division}
};
int evaluate(const std::string &s) {
int a,b;
std::unordered_map<char, decltype(&plus)>::iterator iter;
for (char c : s) {
if (std::isdigit(c)) {
stack.push(c - '0');
} else {
if (stack.size() >= 2 ) {
iter = map.find(c);
if (iter != map.end()) {
a = stack.top();
stack.pop();
b = stack.top();
stack.pop();
stack.push(iter->second(b, a));
} else {
throw std::invalid_argument("Ungueltige Sonderzeichen");
}
} else {
throw std::invalid_argument("Ungueltige Anzahl an Zahlen");
}
}
/*switch (c) {
case '+':
if (stack.size() >= 2) {
a = stack.top();
stack.pop();
b = stack.top();
stack.pop();
stack.push(a + b);
}
break;
case '-':
if (stack.size() >= 2) {
a = stack.top();
stack.pop();
b = stack.top();
stack.pop();stack.push(b - a);
}
break;
case '*':
if (stack.size() >= 2) {
a = stack.top();
stack.pop();
b = stack.top();
stack.pop();stack.push(a * b);
}
break;
case '/':
if (stack.size() >= 2) {
a = stack.top();
stack.pop();
b = stack.top();
if (a == 0) {
throw std::invalid_argument("Division durch 0!");
}
stack.pop();stack.push(b / a);
}
break;
default:
if (std::isdigit(c)) {
stack.push(c - '0');
}
break;
}*/
}
if (stack.size() > 1 || stack.size() == 0) {
throw std::invalid_argument("Ungueltige Eingabe");
}
return stack.top();
}
int main() {
std::string user_input;
std::cin >> user_input;
if (user_input.empty()) { std::cout << "Empty input\n"; return 1; }
std::cout << "User input is \"" << user_input << "\"\n";
int result = INT_MAX;
try {
result = evaluate(user_input);
} catch (const std::exception &e) {
std::cout << e.what();
}
if (result != INT_MAX) {
std::cout << "Result is: " << result << '\n';
}
}
builtins.fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/859ce47b023d80ccbcf446a112c813972a5949b6.tar.gz";
sha256 = "14rmrpzbxbf8p4v70n39bvxm9qhnwlg4pjkzf7ya6n697g8yd1wx";
}
result 0 → 120000
/nix/store/d9ricvlvw0lq3zkyd905k8fir4zlhzcq-fuzzer-example
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment