-
Notifications
You must be signed in to change notification settings - Fork 50
/
giftcardexamplewriter.c
69 lines (58 loc) · 2.14 KB
/
giftcardexamplewriter.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
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Gift Card Example Writer
* Original Author: Shoddycorp's Cut-Rate Contracting
* Maintainer: ???
* Comments added by Justin Cappos (JAC)
* Modification Date: 8 July 2020
*/
#include <stdio.h>
#include "giftcard.h"
/* JAC: Why is this included? */
#include <time.h>
struct this_gift_card examplegc;
struct gift_card_data examplegcd;
struct gift_card_record_data examplegcrd;
struct gift_card_amount_change examplegcac;
// Break it up so that we don't have long functions! Good programming style!
// (JAC: This is so wrong. Global variable use / initialization is a
// terrible thing to do.)
void setupgc() {
examplegc.num_bytes = 116;
examplegc.gift_card_data = (void *) &examplegcd;
examplegcd.merchant_id = "GiftCardz.com ";
examplegcd.customer_id = "DuaneGreenes Store 1451 ";
examplegcd.number_of_gift_card_records = 1;
/* JAC: Something seems fishy... */
examplegcd.gift_card_record_data = malloc(examplegcd.number_of_gift_card_records);
/* JAC: here too! */
examplegcd.gift_card_record_data[0] = (void *) &examplegcrd;
examplegcrd.record_size_in_bytes = 44;
examplegcrd.type_of_record = 1; // JAC: Should be enum! amount_change
examplegcrd.actual_record = (void *) &examplegcac;
examplegcac.amount_added = 2000;
examplegcac.actual_signature = "[ insert crypto signature here ]";
}
// moved into separate files to avoid erroenous style checker error...
/* JAC: opening and writing a fixed filename using a global is terrible style.
* the style checker was right! This code is terrible
*/
void writegc() {
FILE *fd1;
// JAC: Why don't any of these check for error return codes?!?
fd1 = fopen("examplefile.gft","w");
fwrite(&examplegc.num_bytes,4,1,fd1);
fwrite(examplegcd.merchant_id,32,1,fd1);
fwrite(examplegcd.customer_id,32,1,fd1);
fwrite(&examplegcd.number_of_gift_card_records,4,1,fd1);
fwrite(&examplegcrd.record_size_in_bytes,4,1,fd1);
fwrite(&examplegcrd.type_of_record,4,1,fd1);
fwrite(&examplegcac.amount_added,4,1,fd1);
fwrite(examplegcac.actual_signature,32,1,fd1);
fclose(fd1);
}
/* JAC: No args and return -1 for no reason!?! */
int main(void) {
setupgc();
writegc();
return -1;
}