forked from capablevms/cheri-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.c
56 lines (48 loc) · 775 Bytes
/
function.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/***
* Inspect capabilities metadata of a simple function's address.
* The simple function is gcd (Greatest Common Divisor).
***/
#include "include/common.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int gcd(int a, int b)
{
if (0 == a)
{
return b;
}
else if (0 == b)
{
return a;
}
else if (a == b)
{
return a;
}
else if (a > b)
{
return gcd(a - b, b);
}
return gcd(a, b - a);
}
int main()
{
int a, b = 0;
printf("Enter first number:");
if (0 == scanf("%d", &a))
{
error("Extraneous input");
return -1;
}
printf("Enter second number:");
if (0 == scanf("%d", &b))
{
error("Extraneous input");
return -1;
}
int c_gcd = gcd(a, b);
printf("The gcd of these numbers is: %d\n", c_gcd);
pp_cap(*gcd);
return 0;
}