summaryrefslogtreecommitdiff
path: root/user/readstat/big-endian.patch
blob: 71f1db133c71c156584a4d9bd839f44f8932a0ca (plain) (blame)
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
69
70
71
72
73
74
75
76
From 0034c8ee693563cbecae8fa8a24d3e8d5dcc6ab1 Mon Sep 17 00:00:00 2001
From: Evan Miller <emmiller@gmail.com>
Date: Sat, 4 May 2024 08:50:28 -0400
Subject: [PATCH] [SAS7BCAT writer] big-endian architecture fix

Closes #302
---
 src/sas/readstat_sas7bcat_write.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/sas/readstat_sas7bcat_write.c b/src/sas/readstat_sas7bcat_write.c
index 6544798c..9642fdad 100644
--- a/src/sas/readstat_sas7bcat_write.c
+++ b/src/sas/readstat_sas7bcat_write.c
@@ -63,7 +63,8 @@ static sas7bcat_block_t *sas7bcat_block_for_label_set(readstat_label_set_t *r_la
 
     for (j=0; j<r_label_set->value_labels_count; j++) {
         readstat_value_label_t *value_label = readstat_get_value_label(r_label_set, j);
-        lbp1[2] = 24; // size - 6
+        int16_t value_entry_len = 24; // size - 6
+        memcpy(&lbp1[2], &value_entry_len, sizeof(int16_t));
         int32_t index = j;
         memcpy(&lbp1[10], &index, sizeof(int32_t));
         if (r_label_set->type == READSTAT_TYPE_STRING) {
@@ -86,7 +87,7 @@ static sas7bcat_block_t *sas7bcat_block_for_label_set(readstat_label_set_t *r_la
         memcpy(&lbp2[8], &label_len, sizeof(int16_t));
         memcpy(&lbp2[10], value_label->label, label_len);
 
-        lbp1 += 30;
+        lbp1 += 6 + value_entry_len;
         lbp2 += 8 + 2 + value_label->label_len + 1;
     }
 
From 29aac3db79a5da20d1d1dcbb54a587c5ba51e7b3 Mon Sep 17 00:00:00 2001
From: Evan Miller <emmiller@gmail.com>
Date: Sat, 4 May 2024 10:35:27 -0400
Subject: [PATCH] [SAS7BCAT writer] more big-endian fixes

---
 src/sas/readstat_sas7bcat_write.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/sas/readstat_sas7bcat_write.c b/src/sas/readstat_sas7bcat_write.c
index 9642fda..c25fec0 100644
--- a/src/sas/readstat_sas7bcat_write.c
+++ b/src/sas/readstat_sas7bcat_write.c
@@ -46,7 +46,8 @@ static sas7bcat_block_t *sas7bcat_block_for_label_set(readstat_label_set_t *r_la
     memcpy(&block->data[38], &count, sizeof(int32_t));
     memcpy(&block->data[42], &count, sizeof(int32_t));
     if (name_len > 8) {
-        block->data[2] = (char)0x80;
+        int16_t flags = 0x80;
+        memcpy(&block->data[2], &flags, sizeof(int16_t));
         memcpy(&block->data[8], name, 8);
 
         memset(&block->data[106], ' ', 32);
@@ -139,16 +140,15 @@ static readstat_error_t sas7bcat_begin_data(void *writer_ctx) {
 
     // Page 1
     char *xlsr = &page[856];
-    int16_t block_idx, block_off;
-    block_idx = 4;
-    block_off = 16;
+    int32_t block_idx = 4;
+    int16_t block_off = 16;
     for (i=0; i<writer->label_sets_count; i++) {
         if (xlsr + 212 > page + hinfo->page_size)
             break;
 
         memcpy(&xlsr[0], "XLSR", 4);
 
-        memcpy(&xlsr[4], &block_idx, sizeof(int16_t));
+        memcpy(&xlsr[4], &block_idx, sizeof(int32_t));
         memcpy(&xlsr[8], &block_off, sizeof(int16_t));
 
         xlsr[50] = 'O';