Skip to content

Commit 19522e0

Browse files
committed
Win: move to safe version of sscanf
sscanf is known to cause problems on many architectures, so on Windows, move to the safer version sscanf_s, downside - this does require different arguments sometimes. Signed-off-by: Robin Getz <[email protected]>
1 parent 2e400fa commit 19522e0

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

iio-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#ifdef _MSC_BUILD
3030
#define inline __inline
3131
#define iio_snprintf sprintf_s
32+
#define iio_sscanf sscanf_s
3233
#else
3334
#define iio_snprintf snprintf
35+
#define iio_sscanf sscanf
3436
#endif
3537

3638
#ifdef _WIN32

iiod-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static int iiod_client_read_mask(struct iiod_client *client,
588588
IIO_DEBUG("Reading mask\n");
589589

590590
for (i = words, ptr = buf; i > 0; i--) {
591-
sscanf(ptr, "%08" PRIx32, &mask[i - 1]);
591+
iio_sscanf(ptr, "%08" PRIx32, &mask[i - 1]);
592592
IIO_DEBUG("mask[%lu] = 0x%08" PRIx32 "\n",
593593
(unsigned long)(i - 1), mask[i - 1]);
594594

local.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,24 @@ static int handle_protected_scan_element_attr(struct iio_channel *chn,
12301230
char endian, sign;
12311231

12321232
if (strchr(buf, 'X')) {
1233-
sscanf(buf, "%ce:%c%u/%uX%u>>%u", &endian, &sign,
1233+
iio_sscanf(buf, "%ce:%c%u/%uX%u>>%u",
1234+
#ifdef _MSC_BUILD
1235+
&endian, sizeof(endian),
1236+
&sign, sizeof(sign),
1237+
#else
1238+
&endian, &sign,
1239+
#endif
12341240
&chn->format.bits, &chn->format.length,
12351241
&chn->format.repeat, &chn->format.shift);
12361242
} else {
12371243
chn->format.repeat = 1;
1238-
sscanf(buf, "%ce:%c%u/%u>>%u", &endian, &sign,
1244+
iio_sscanf(buf, "%ce:%c%u/%u>>%u",
1245+
#ifdef _MSC_BUILD
1246+
&endian, sizeof(endian),
1247+
&sign, sizeof(sign),
1248+
#else
1249+
&endian, &sign,
1250+
#endif
12391251
&chn->format.bits, &chn->format.length,
12401252
&chn->format.shift);
12411253
}

network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ static ssize_t network_read_mask(struct iio_network_io_context *io_ctx,
771771
if (ret < 0)
772772
return ret;
773773

774-
sscanf(buf, "%08x", &mask[i - 1]);
774+
iio_sscanf(buf, "%08x", &mask[i - 1]);
775775
IIO_DEBUG("mask[%lu] = 0x%x\n",
776776
(unsigned long)(i - 1), mask[i - 1]);
777777
}

xml.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,24 @@ static void setup_scan_element(struct iio_channel *chn, xmlNode *n)
143143
} else if (!strcmp(name, "format")) {
144144
char e, s;
145145
if (strchr(content, 'X')) {
146-
sscanf(content, "%ce:%c%u/%uX%u>>%u", &e, &s,
146+
iio_sscanf(content, "%ce:%c%u/%uX%u>>%u",
147+
#ifdef _MSC_BUILD
148+
&e, sizeof(e), &s, sizeof(s),
149+
#else
150+
&e, &s,
151+
#endif
147152
&chn->format.bits,
148153
&chn->format.length,
149154
&chn->format.repeat,
150155
&chn->format.shift);
151156
} else {
152157
chn->format.repeat = 1;
153-
sscanf(content, "%ce:%c%u/%u>>%u", &e, &s,
158+
iio_sscanf(content, "%ce:%c%u/%u>>%u",
159+
#ifdef _MSC_BUILD
160+
&e, sizeof(e), &s, sizeof(s),
161+
#else
162+
&e, &s,
163+
#endif
154164
&chn->format.bits,
155165
&chn->format.length,
156166
&chn->format.shift);

0 commit comments

Comments
 (0)