Now it doesn't rely on malloc, which can be tricky to get to work in and
of itself.
def test_function_call(self):
self.gdb.b("main:start")
self.gdb.c()
- text = "Howdy, Earth!"
- gdb_length = self.gdb.p('strlen("%s")' % text)
- self.assertEqual(gdb_length, len(text))
+ self.assertEqual(self.gdb.p('fib(6)'), 8)
+ self.assertEqual(self.gdb.p('fib(7)'), 13)
self.exit()
def test_change_string(self):
unsigned int crc32a(uint8_t *message, unsigned int size);
+unsigned int fib(unsigned int n)
+{
+ if (n == 0) {
+ return 0;
+ }
+
+ unsigned int a = 0;
+ unsigned int b = 1;
+
+ for (unsigned int i = 1; i < n; i++) {
+ unsigned int next = a + b;
+ a = b;
+ b = next;
+ }
+
+ return b;
+}
+
void rot13(char *buf)
{
while (*buf) {