Skip to content

Commit 74ed58e

Browse files
committed
Fix spatial/temporal neo4j_fprint() return value
The spatial and temporal *_fprint functions relied on the positive return value of fputs() being the number of bytes written, but that's undefined behaviour in ISO C. This change replaces fputs() with fprintf().
1 parent 4d0a242 commit 74ed58e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/src/print.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,12 +1101,13 @@ ssize_t neo4j_date_str(const neo4j_value_t *value, char *buf, size_t n)
11011101
}
11021102

11031103
ssize_t neo4j_date_fprint(const neo4j_value_t *value, FILE *stream) {
1104+
REQUIRE(value != NULL, -1);
11041105
assert(neo4j_type(*value) == NEO4J_DATE);
11051106
char buf[BUFLEN];
11061107
if (neo4j_date_str(value, buf, BUFLEN-1) < 0) {
11071108
return -1;
11081109
}
1109-
return fputs( (const char *)buf, stream );
1110+
return fprintf( stream, "%s", (const char *)buf );
11101111
}
11111112

11121113
/* time : prints time of day and UTC offset string, with time_t value in parens;
@@ -1152,12 +1153,13 @@ ssize_t neo4j_time_str(const neo4j_value_t *value, char *buf, size_t n)
11521153
}
11531154

11541155
ssize_t neo4j_time_fprint(const neo4j_value_t *value, FILE *stream) {
1156+
REQUIRE(value != NULL, -1);
11551157
assert(neo4j_type(*value) == NEO4J_TIME);
11561158
char buf[BUFLEN];
11571159
if (neo4j_time_str(value, buf, BUFLEN-1) < 0) {
11581160
return -1;
11591161
}
1160-
return fputs( (const char *)buf, stream );
1162+
return fprintf( stream, "%s", (const char *)buf );
11611163
}
11621164

11631165
/* localtime */
@@ -1200,12 +1202,13 @@ ssize_t neo4j_localtime_str(const neo4j_value_t *value, char *buf, size_t n)
12001202
}
12011203

12021204
ssize_t neo4j_localtime_fprint(const neo4j_value_t *value, FILE *stream) {
1205+
REQUIRE(value != NULL, -1);
12031206
assert(neo4j_type(*value) == NEO4J_LOCALTIME);
12041207
char buf[BUFLEN];
12051208
if (neo4j_localtime_str(value, buf, BUFLEN-1) < 0) {
12061209
return -1;
12071210
}
1208-
return fputs( (const char *)buf, stream );
1211+
return fprintf( stream, "%s", (const char *)buf );
12091212
}
12101213

12111214
/* datetime */
@@ -1251,12 +1254,13 @@ ssize_t neo4j_datetime_str(const neo4j_value_t *value, char *buf, size_t n)
12511254
}
12521255

12531256
ssize_t neo4j_datetime_fprint(const neo4j_value_t *value, FILE *stream) {
1257+
REQUIRE(value != NULL, -1);
12541258
assert(neo4j_type(*value) == NEO4J_DATETIME);
12551259
char buf[BUFLEN];
12561260
if (neo4j_datetime_str(value, buf, BUFLEN-1) < 0) {
12571261
return -1;
12581262
}
1259-
return fputs( (const char *)buf, stream );
1263+
return fprintf( stream, "%s", (const char *)buf );
12601264
}
12611265

12621266
/* localdatetime */
@@ -1299,12 +1303,13 @@ ssize_t neo4j_localdatetime_str(const neo4j_value_t *value, char *buf, size_t n)
12991303
}
13001304

13011305
ssize_t neo4j_localdatetime_fprint(const neo4j_value_t *value, FILE *stream) {
1306+
REQUIRE(value != NULL, -1);
13021307
assert(neo4j_type(*value) == NEO4J_LOCALDATETIME);
13031308
char buf[BUFLEN];
13041309
if (neo4j_localdatetime_str(value, buf, BUFLEN-1) < 0) {
13051310
return -1;
13061311
}
1307-
return fputs( (const char *)buf, stream );
1312+
return fprintf( stream, "%s", (const char *)buf );
13081313
}
13091314

13101315
/* duration */
@@ -1392,12 +1397,13 @@ ssize_t neo4j_duration_str(const neo4j_value_t *value, char *buf, size_t n)
13921397
}
13931398

13941399
ssize_t neo4j_duration_fprint(const neo4j_value_t *value, FILE *stream) {
1400+
REQUIRE(value != NULL, -1);
13951401
assert(neo4j_type(*value) == NEO4J_DURATION);
13961402
char buf[BUFLEN];
13971403
if (neo4j_duration_str(value, buf, BUFLEN-1) < 0) {
13981404
return -1;
13991405
}
1400-
return fputs( (const char *)buf, stream );
1406+
return fprintf( stream, "%s", (const char *)buf );
14011407
}
14021408

14031409
/* point2d */
@@ -1432,12 +1438,13 @@ ssize_t neo4j_point2d_str(const neo4j_value_t *value, char *buf, size_t n)
14321438

14331439

14341440
ssize_t neo4j_point2d_fprint(const neo4j_value_t *value, FILE *stream) {
1441+
REQUIRE(value != NULL, -1);
14351442
assert(neo4j_type(*value) == NEO4J_POINT2D);
14361443
char buf[BUFLEN];
14371444
if (neo4j_point2d_str(value, buf, BUFLEN-1) < 0) {
14381445
return -1;
14391446
}
1440-
return fputs( (const char *)buf, stream );
1447+
return fprintf( stream, "%s", (const char *)buf );
14411448
}
14421449

14431450
/* point3d */
@@ -1472,10 +1479,11 @@ ssize_t neo4j_point3d_str(const neo4j_value_t *value, char *buf, size_t n)
14721479
}
14731480

14741481
ssize_t neo4j_point3d_fprint(const neo4j_value_t *value, FILE *stream) {
1482+
REQUIRE(value != NULL, -1);
14751483
assert(neo4j_type(*value) == NEO4J_POINT3D);
14761484
char buf[BUFLEN];
14771485
if (neo4j_point3d_str(value, buf, BUFLEN-1) < 0) {
14781486
return -1;
14791487
}
1480-
return fputs( (const char *)buf, stream );
1488+
return fprintf( stream, "%s", (const char *)buf );
14811489
}

0 commit comments

Comments
 (0)