Commit 5e750f29eee0eca0c8944648e97d78c1caa44e76

James Humphrey 2019-03-24T16:47:46

Enable -Weverything and eliminate warnings Only a few warnings have been disabled in the Makefile. Also changed the smtp_attachment_add_mem interface to use a size_t for the datasz parameter.

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
diff --git a/Makefile b/Makefile
index 128e23b..4edc26d 100644
--- a/Makefile
+++ b/Makefile
@@ -17,8 +17,6 @@
 BDIR = build
 INSTALL_PREFIX = /usr/local
 
-SILENT = @
-
 CWARN += -Waggregate-return
 CWARN += -Wall
 CWARN += -Wbad-function-cast
@@ -42,6 +40,7 @@ CWARN += -Wmissing-declarations
 CWARN += -Wmissing-include-dirs
 CWARN += -Wmissing-prototypes
 CWARN += -Wnested-externs
+CWARN += -Wnull-dereference
 CWARN += -Wold-style-definition
 CWARN += -Wpacked
 CWARN += -Wpedantic
@@ -50,6 +49,7 @@ CWARN += -Wredundant-decls
 CWARN += -Wshadow
 CWARN += -Wstack-protector
 CWARN += -Wstrict-aliasing
+CWARN += -Wstrict-overflow=5
 CWARN += -Wstrict-prototypes
 CWARN += -Wswitch-default
 CWARN += -Wswitch-enum
@@ -61,17 +61,24 @@ CWARN += -Wvla
 CWARN += -Wwrite-strings
 
 CWARN.gcc += -Wno-aggressive-loop-optimizations
+CWARN.gcc += -Wduplicated-branches
+CWARN.gcc += -Wduplicated-cond
 CWARN.gcc += -Wjump-misses-init
 CWARN.gcc += -Wlogical-op
 CWARN.gcc += -Wnormalized=nfkc
+CWARN.gcc += -Wrestrict
 CWARN.gcc += -Wstack-usage=5000
+CWARN.gcc += -Wshift-overflow=2
 CWARN.gcc += -Wsync-nand
+CWARN.gcc += -Wstringop-overflow=4
 CWARN.gcc += -Wtrampolines
-CWARN.gcc += -Wunsafe-loop-optimizations
+##CWARN.gcc += -Wunsafe-loop-optimizations
 CWARN.gcc += -Wunsuffixed-float-constants
 CWARN.gcc += -Wvector-operation-performance
 
+CWARN.clang += -Weverything
 CWARN.clang += -Wno-format-nonliteral
+CWARN.clang += -fcomment-block-commands=retval
 
 CFLAGS += $(CWARN)
 CFLAGS += -fstack-protector-all
@@ -85,6 +92,7 @@ CFLAGS.debug   += -g3
 CFLAGS.debug   += -DSMTP_TEST
 CFLAGS.debug   += -Wno-missing-prototypes
 CFLAGS.debug   += -fprofile-arcs -ftest-coverage
+CFLAGS.debug += -ftrapv
 
 CFLAGS.clang   += -fsanitize=undefined
 
@@ -101,6 +109,8 @@ CFLAGS.gcc.debug     += $(CFLAGS.debug) $(CWARN.gcc)
 CFLAGS.gcc.release   += $(CFLAGS.release) $(CWARN.gcc)
 CFLAGS.clang.debug   += $(CFLAGS.debug) $(CFLAGS.clang) $(CWARN.clang)
 
+CDEF_POSIX = -D_POSIX_C_SOURCE=200112
+
 SCAN_BUILD = $(SILENT) scan-build -maxloop 100          \
                                   -o $(BDIR)/scan-build \
                                   --status-bugs         \
@@ -242,13 +252,13 @@ $(BDIR)/release/test_cpp_wrapper.o: test/test_cpp_wrapper.cpp | $(BDIR)/release
 	$(COMPILE.cpp.release) -Isrc
 
 $(BDIR)/debug/smtp.o: src/smtp.c | $(BDIR)/debug
-	$(COMPILE.c.debug)
+	$(COMPILE.c.debug) $(CDEF_POSIX)
 
 $(BDIR)/release/smtp_nossl.o: src/smtp.c | $(BDIR)/release
-	$(COMPILE.c.release) -USMTP_OPENSSL
+	$(COMPILE.c.release) $(CDEF_POSIX) -USMTP_OPENSSL
 
 $(BDIR)/release/smtp.o: src/smtp.c | $(BDIR)/release
-	$(COMPILE.c.release)
+	$(COMPILE.c.release) $(CDEF_POSIX)
 
 $(BDIR)/debug/test: $(BDIR)/debug/seams.o \
                     $(BDIR)/debug/smtp.o  \
@@ -256,10 +266,10 @@ $(BDIR)/debug/test: $(BDIR)/debug/seams.o \
 	$(LINK.c.debug) -lssl -lcrypto -lgcov
 
 $(BDIR)/debug/test.o: test/test.c | $(BDIR)/debug
-	$(COMPILE.c.debug) -Isrc/
+	$(COMPILE.c.debug) $(CDEF_POSIX) -Isrc/
 
 $(BDIR)/debug/seams.o: test/seams.c | $(BDIR)/debug
-	$(COMPILE.c.debug)
+	$(COMPILE.c.debug) $(CDEF_POSIX)
 
 $(BDIR)/debug/clang_test: $(BDIR)/debug/clang_seams.o \
                           $(BDIR)/debug/clang_smtp.o  \
@@ -267,13 +277,13 @@ $(BDIR)/debug/clang_test: $(BDIR)/debug/clang_seams.o \
 	$(LINK.c.clang) -lssl -lcrypto -lgcov -lubsan
 
 $(BDIR)/debug/clang_seams.o: test/seams.c | $(BDIR)/debug
-	$(COMPILE.c.clang)
+	$(COMPILE.c.clang) $(CDEF_POSIX)
 
 $(BDIR)/debug/clang_smtp.o: src/smtp.c | $(BDIR)/debug
-	$(COMPILE.c.clang)
+	$(COMPILE.c.clang) $(CDEF_POSIX)
 
 $(BDIR)/debug/clang_test.o: test/test.c | $(BDIR)/debug
-	$(COMPILE.c.clang) -Isrc/
+	$(COMPILE.c.clang) $(CDEF_POSIX) -Isrc/
 
 $(BDIR)/release/test_nossl: $(BDIR)/release/smtp_nossl.o \
                             $(BDIR)/release/test_nossl.o
diff --git a/src/smtp.c b/src/smtp.c
index 61b9b9b..51b5b21 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -30,11 +30,6 @@
 # include <winsock2.h>
 # include <ws2tcpip.h>
 #else /* POSIX */
-/**
- * Need to define this on some POSIX systems in order to get access to the
- * getaddrinfo and localtime_r functions.
- */
-# define _POSIX_C_SOURCE 200112L
 # include <netinet/in.h>
 # include <sys/select.h>
 # include <sys/socket.h>
@@ -104,11 +99,6 @@
  */
 struct smtp_address{
   /**
-   * Specify from, to, cc, bcc.
-   */
-  enum smtp_address_type type;
-
-  /**
    * Email address without any special formatting.
    *
    * For example: mail@example.com
@@ -119,6 +109,16 @@ struct smtp_address{
    * Description of the email address.
    */
   char *name;
+
+  /**
+   * Specify from, to, cc, bcc.
+   */
+  enum smtp_address_type type;
+
+  /**
+   * Padding structure to align.
+   */
+  char pad[4];
 };
 
 /**
@@ -201,18 +201,18 @@ struct smtp{
   size_t num_attachment;
 
   /**
-   * Status code indicating success/failure.
+   * Timeout in seconds to wait before returning with an error.
    *
-   * This code gets returned by most of the header functions.
+   * This applies to both writing to and reading from a network socket.
    */
-  enum smtp_status_code status_code;
+  long timeout_sec;
 
   /**
-   * Timeout in seconds to wait before returning with an error.
+   * Status code indicating success/failure.
    *
-   * This applies to both writing to and reading from a network socket.
+   * This code gets returned by most of the header functions.
    */
-  long timeout_sec;
+  enum smtp_status_code status_code;
 
   /**
    * Indicates if this context has an active TLS connection.
@@ -351,11 +351,11 @@ smtp_si_mul_size_t(const size_t a,
  * Wait until more data has been made available on the socket read end.
  *
  * @param[in] smtp SMTP client context.
- * @retval  0 If data available to read on the socket.
- * @retval -1 If the connection times out before any data appears on the
- *            socket.
+ * @retval SMTP_STATUS_OK   If data available to read on the socket.
+ * @retval SMTP_STATUS_RECV If the connection times out before any data
+ *                          appears on the socket.
  */
-static int
+static enum smtp_status_code
 smtp_str_getdelimfd_read_timeout(struct smtp *const smtp){
   fd_set readfds;
   struct timeval timeout;
@@ -369,7 +369,7 @@ smtp_str_getdelimfd_read_timeout(struct smtp *const smtp){
   if(sel_rc < 1){
     return smtp_status_code_set(smtp, SMTP_STATUS_RECV);
   }
-  return smtp->status_code;
+  return SMTP_STATUS_OK;
 }
 
 /**
@@ -402,7 +402,11 @@ smtp_str_getdelimfd_read(struct str_getdelimfd *const gdfd,
   if(smtp->tls_on){
 #ifdef SMTP_OPENSSL
     do{
-      bytes_read = SSL_read(smtp->tls, buf, count);
+      /*
+       * Count will never have a value greater than SMTP_GETDELIM_READ_SZ,
+       * so we can safely convert this to an int.
+       */
+      bytes_read = SSL_read(smtp->tls, buf, (int)count);
     } while(bytes_read <= 0 && BIO_should_retry(smtp->tls_bio));
 #endif /* SMTP_OPENSSL */
   }
@@ -504,7 +508,7 @@ smtp_str_getdelimfd_free(struct str_getdelimfd *const gdfd){
  * error code.
  *
  * @param[in] gdfd See @ref str_getdelimfd.
- * @return @ref str_getdelim_retcode.
+ * @return See @ref str_getdelim_retcode.
  */
 static enum str_getdelim_retcode
 smtp_str_getdelimfd_throw_error(struct str_getdelimfd *const gdfd){
@@ -520,7 +524,7 @@ smtp_str_getdelimfd_throw_error(struct str_getdelimfd *const gdfd){
  * to the caller for handling.
  *
  * @param[in] gdfd See @ref str_getdelimfd.
- * @return @ref str_getdelim_retcode.
+ * @return See @ref str_getdelim_retcode.
  */
 SMTP_LINKAGE enum str_getdelim_retcode
 smtp_str_getdelimfd(struct str_getdelimfd *const gdfd){
@@ -579,7 +583,9 @@ smtp_str_getdelimfd(struct str_getdelimfd *const gdfd){
                                           read_buf_ptr,
                                           SMTP_GETDELIM_READ_SZ);
     if(bytes_read < 0 ||
-       smtp_si_add_size_t(gdfd->_buf_len, bytes_read, &gdfd->_buf_len)){
+       smtp_si_add_size_t(gdfd->_buf_len,
+                          (size_t)bytes_read,
+                          &gdfd->_buf_len)){
       return smtp_str_getdelimfd_throw_error(gdfd);
     }
   }
@@ -770,7 +776,7 @@ smtp_str_replace(const char *const search,
  * table. Since 2^6 = 64, this array has 64 entries which maps directly from
  * the 6 bit value into the corresponding array value.
  */
-static unsigned char g_base64_encode_table[] = {
+static char g_base64_encode_table[] = {
   'A','B','C','D','E','F','G','H','I','J',
   'K','L','M','N','O','P','Q','R','S','T',
   'U','V','W','X','Y','Z',
@@ -919,12 +925,12 @@ g_base64_decode_table[] = {
  * @param[in]  buf    Buffer containing bytes to decode.
  * @param[out] decode Buffer for storing base64 decoded bytes.
  * @retval >0 Length of the decoded block.
- * @retval -1 If the block contains invalid base64 data.
+ * @retval  0 If the block contains invalid base64 data.
  */
-static int
+static size_t
 smtp_base64_decode_block(const unsigned char *const buf,
                          unsigned char *const decode){
-  int decode_block_len;
+  size_t decode_block_len;
   size_t i;
   signed char decode_table[4];
   unsigned char outb[3];
@@ -937,7 +943,7 @@ smtp_base64_decode_block(const unsigned char *const buf,
     }
     decode_table[i] = g_base64_decode_table[buf[i]];
     if(decode_table[i] < 0){
-      return -1;
+      return 0;
     }
   }
 
@@ -981,35 +987,36 @@ smtp_base64_decode_block(const unsigned char *const buf,
  * @retval >=0 Length of the data stored in the decode parameter.
  * @retval -1  Memory allocation failure or invalid base64 byte sequences.
  */
-SMTP_LINKAGE long
+SMTP_LINKAGE size_t
 smtp_base64_decode(const char *const buf,
                    unsigned char **decode){
   size_t buf_len;
   size_t buf_len_inc;
   size_t buf_i;
   unsigned char *b64_decode;
-  long decode_len;
-  int decode_block_len;
+  size_t decode_len;
+  size_t decode_block_len;
 
   *decode = NULL;
 
   buf_len = strlen(buf);
   if(buf_len % 4 != 0){
-    return -1;
+    return SIZE_MAX;
   }
 
   if(smtp_si_add_size_t(buf_len, 1, &buf_len_inc) ||
      (b64_decode = calloc(1, buf_len_inc)) == NULL){
-    return -1;
+    return SIZE_MAX;
   }
 
   decode_len = 0;
   for(buf_i = 0; buf_i < buf_len; buf_i += 4){
-    if((decode_block_len = smtp_base64_decode_block(
-                             (const unsigned char*)&buf[buf_i],
-                             &b64_decode[decode_len])) < 0){
+    decode_block_len = smtp_base64_decode_block(
+                         (const unsigned char*)&buf[buf_i],
+                         &b64_decode[decode_len]);
+    if(decode_block_len == 0){
       free(b64_decode);
-      return -1;
+      return SIZE_MAX;
     }
     decode_len += decode_block_len;
   }
@@ -1046,13 +1053,15 @@ smtp_bin2hex(const unsigned char *const s,
     return NULL;
   }
 
-  for(i = 0, j = 0; i < slen; i++, j += 2){
+  j = 0;
+  for(i = 0; i < slen; i++){
     hex = s[i];
     rc = sprintf(&snew[j], "%02x", hex);
     if(rc < 0 || (size_t)rc >= 3){
       free(snew);
       return NULL;
     }
+    j += 2;
   }
   snew[j] = '\0';
 
@@ -1072,22 +1081,25 @@ smtp_bin2hex(const unsigned char *const s,
  * @retval >0 Number of bytes for the current UTF-8 character sequence.
  * @retval -1 Invalid byte sequence.
  */
-SMTP_LINKAGE int
-smtp_utf8_charlen(unsigned char c){
-  if((c & 0x80) == 0){         /* 0XXXXXXX */
+SMTP_LINKAGE size_t
+smtp_utf8_charlen(char c){
+  unsigned char uc;
+
+  uc = (unsigned char)c;
+  if((uc & 0x80) == 0){         /* 0XXXXXXX */
     return 1;
   }
-  else if((c & 0xE0) == 0xC0){ /* 110XXXXX */
+  else if((uc & 0xE0) == 0xC0){ /* 110XXXXX */
     return 2;
   }
-  else if((c & 0xF0) == 0xE0){ /* 1110XXXX */
+  else if((uc & 0xF0) == 0xE0){ /* 1110XXXX */
     return 3;
   }
-  else if((c & 0xF8) == 0xF0){ /* 11110XXX */
+  else if((uc & 0xF8) == 0xF0){ /* 11110XXX */
     return 4;
   }
   else{                        /* invalid  */
-    return -1;
+    return 0;
   }
 }
 
@@ -1103,8 +1115,8 @@ smtp_utf8_charlen(unsigned char c){
  */
 SMTP_LINKAGE int
 smtp_str_has_nonascii_utf8(const char *const s){
-  int i;
-  int charlen;
+  size_t i;
+  size_t charlen;
 
   for(i = 0; s[i]; i++){
     charlen = smtp_utf8_charlen(s[i]);
@@ -1129,22 +1141,22 @@ smtp_str_has_nonascii_utf8(const char *const s){
  * @retval maxlen    If length of s has more bytes than maxlen.
  * @retval -1        If @p s contains an invalid UTF-8 byte sequence.
  */
-SMTP_LINKAGE long
+SMTP_LINKAGE size_t
 smtp_strnlen_utf8(const char *s,
                   size_t maxlen){
   size_t i;
-  int utf8_i;
-  int utf8_len;
+  size_t utf8_i;
+  size_t utf8_len;
 
   for(i = 0; *s && i < maxlen; i += utf8_len){
     utf8_len = smtp_utf8_charlen(*s);
-    if(utf8_len < 0){
-      return -1;
+    if(utf8_len == 0){
+      return SIZE_MAX;
     }
 
     for(utf8_i = 0; utf8_i < utf8_len; utf8_i++){
       if(!*s){
-        return -1;
+        return SIZE_MAX;
       }
       s += 1;
     }
@@ -1316,7 +1328,7 @@ smtp_chunk_split(const char *const s,
   size_t chunk_i;
   size_t snew_i;
   size_t body_i;
-  long body_copy_len;
+  size_t body_copy_len;
 
   if(chunklen < 1){
     errno = EINVAL;
@@ -1346,9 +1358,8 @@ smtp_chunk_split(const char *const s,
   snew_i = 0;
   for(chunk_i = 0; chunk_i < bodylen / chunklen + 1; chunk_i++){
     body_copy_len = smtp_strnlen_utf8(&s[body_i], chunklen);
-    if(body_copy_len < 0){
+    if(body_copy_len == SIZE_MAX){
       free(snew);
-      errno = EINVAL;
       return NULL;
     }
     memcpy(&snew[snew_i], &s[body_i], body_copy_len);
@@ -1465,6 +1476,7 @@ smtp_parse_cmd_line(char *const line,
   char *ep;
   char code_str[4];
   size_t line_len;
+  unsigned long int ulcode;
 
   line_len = strlen(line);
   if(line_len < 5){
@@ -1478,10 +1490,14 @@ smtp_parse_cmd_line(char *const line,
 
   memcpy(code_str, line, 3);
   code_str[3] = '\0';
-  cmd->code = strtoul(code_str, &ep, 10);
-  if(*ep != '\0'){
+  ulcode = strtoul(code_str, &ep, 10);
+  if(*ep != '\0' || ulcode > SMTP_BEGIN_MAIL){
     cmd->code = SMTP_INTERNAL_ERROR;
   }
+  else{
+    cmd->code = (enum smtp_result_code)ulcode;
+  }
+
   cmd->more = line[3] == '-' ? 1 : 0;
   return cmd->code;
 }
@@ -1524,7 +1540,7 @@ smtp_puts_dbg(struct smtp *const smtp,
  * Read a server response line.
  *
  * @param[in] smtp SMTP client context.
- * @return @ref str_getdelim_retcode.
+ * @return See @ref str_getdelim_retcode.
  */
 static enum str_getdelim_retcode
 smtp_getline(struct smtp *const smtp){
@@ -1554,7 +1570,7 @@ smtp_getline(struct smtp *const smtp){
  * then return the status code from the last response line.
  *
  * @param[in] smtp SMTP client context.
- * @return @ref smtp_result_code.
+ * @return See @ref smtp_result_code.
  */
 static int
 smtp_read_and_parse_code(struct smtp *const smtp){
@@ -1583,15 +1599,16 @@ smtp_read_and_parse_code(struct smtp *const smtp){
  * @param[in] smtp SMTP client context.
  * @param[in] buf Data to send to the SMTP server.
  * @param[in] len Number of bytes in buf.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 SMTP_LINKAGE enum smtp_status_code
 smtp_write(struct smtp *const smtp,
            const char *const buf,
            size_t len){
   size_t bytes_to_send;
-  int bytes_sent;
+  long bytes_sent;
   const char *buf_offset;
+  int ssl_bytes_to_send;
 
   smtp_puts_dbg(smtp, "Client", buf);
 
@@ -1604,13 +1621,16 @@ smtp_write(struct smtp *const smtp,
 
     if(smtp->tls_on){
 #ifdef SMTP_OPENSSL
-      bytes_sent = SSL_write(smtp->tls, buf_offset, bytes_to_send);
+      /* bytes_to_send <= INT_MAX */
+      ssl_bytes_to_send = (int)bytes_to_send;
+      bytes_sent = SSL_write(smtp->tls, buf_offset, ssl_bytes_to_send);
       if(bytes_sent <= 0){
         return smtp_status_code_set(smtp, SMTP_STATUS_SEND);
       }
 #else /* !(SMTP_OPENSSL) */
       /* unreachable */
       bytes_sent = 0;
+      (void)ssl_bytes_to_send;
 #endif /* SMTP_OPENSSL */
     }
     else{
@@ -1619,7 +1639,7 @@ smtp_write(struct smtp *const smtp,
         return smtp_status_code_set(smtp, SMTP_STATUS_SEND);
       }
     }
-    bytes_to_send -= bytes_sent;
+    bytes_to_send -= (size_t)bytes_sent;
     buf_offset += bytes_sent;
   }
 
@@ -1650,7 +1670,7 @@ smtp_puts(struct smtp *const smtp,
 static enum smtp_status_code
 smtp_puts_terminate(struct smtp *const smtp,
                     const char *const s){
-  int rc;
+  enum smtp_status_code rc;
   char *line;
   char *concat;
   size_t slen;
@@ -1846,15 +1866,13 @@ smtp_tls_init(struct smtp *const smtp,
  * later on when we try to use that extension.
  *
  * @param[in] smtp SMTP client context.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_ehlo(struct smtp *const smtp){
-  if(smtp_puts(smtp, "EHLO smtp\r\n") != SMTP_STATUS_OK){
-    return smtp->status_code;
+  if(smtp_puts(smtp, "EHLO smtp\r\n") == SMTP_STATUS_OK){
+    smtp_read_and_parse_code(smtp);
   }
-
-  smtp_read_and_parse_code(smtp);
   return smtp->status_code;
 }
 
@@ -1865,7 +1883,7 @@ smtp_ehlo(struct smtp *const smtp){
  *      or as shown in the format string: "\0%s\0%s", email, password.
  *   2. Base64 encode the text from (1).
  *   3. Send the constructed auth text from (2) to the server:
- *      "AUTH PLAIN <b64>\r\n".
+ *      "AUTH PLAIN <b64><CR><NL>".
  *
  * @param[in] smtp SMTP client context.
  * @param[in] user SMTP account user name.
@@ -1936,9 +1954,9 @@ smtp_auth_plain(struct smtp *const smtp,
  *
  *   1. Base64 encode the user name.
  *   2. Send string from (1) as part of the login:
- *      "AUTH LOGIN <b64_username>\r\n".
+ *      "AUTH LOGIN <b64_username><CR><NL>".
  *   3. Base64 encode the password and send that by itself on a separate
- *      line: "<b64_password>\r\n".
+ *      line: "<b64_password><CR><NL>".
  *
  * @param[in] smtp SMTP client context.
  * @param[in] user SMTP account user name.
@@ -1957,7 +1975,7 @@ smtp_auth_login(struct smtp *const smtp,
   char *concat;
 
   /* (1) */
-  if((b64_user = smtp_base64_encode(user, -1)) == NULL){
+  if((b64_user = smtp_base64_encode(user, SIZE_MAX)) == NULL){
     return -1;
   }
 
@@ -1984,7 +2002,7 @@ smtp_auth_login(struct smtp *const smtp,
   }
 
   /* (3) */
-  if((b64_pass = smtp_base64_encode(pass, -1)) == NULL){
+  if((b64_pass = smtp_base64_encode(pass, SIZE_MAX)) == NULL){
     return -1;
   }
   smtp_puts_terminate(smtp, b64_pass);
@@ -2003,7 +2021,7 @@ smtp_auth_login(struct smtp *const smtp,
 /**
  * Authenticate using the CRAM-MD5 method.
  *
- *   1. Send "AUTH CRAM-MD5\r\n" to the server.
+ *   1. Send "AUTH CRAM-MD5<CR><NL>" to the server.
  *   2. Decode the base64 challenge response from the server.
  *   3. Do an MD5 HMAC on (2) using the account password as the key.
  *   4. Convert the binary data in (3) to lowercase hex characters.
@@ -2023,7 +2041,7 @@ smtp_auth_cram_md5(struct smtp *const smtp,
                    const char *const pass){
   struct smtp_command cmd;
   unsigned char *challenge_decoded;
-  long challenge_decoded_len;
+  size_t challenge_decoded_len;
   const char *key;
   int key_len;
   unsigned char hmac[EVP_MAX_MD_SIZE];
@@ -2049,18 +2067,22 @@ smtp_auth_cram_md5(struct smtp *const smtp,
   }
 
   /* (2) */
-  challenge_decoded_len = smtp_base64_decode(cmd.text, &challenge_decoded);
-  if(challenge_decoded_len < 0){
+  challenge_decoded_len = smtp_base64_decode(cmd.text,
+                                             &challenge_decoded);
+  if(challenge_decoded_len == SIZE_MAX){
     return -1;
   }
 
   /* (3) */
   key = pass;
-  key_len = strlen(pass);
+  key_len = (int)strlen(pass);/*********************cast*/
   hmac_ret = HMAC(EVP_md5(),
-                  key, key_len,
-                  challenge_decoded, challenge_decoded_len,
-                  hmac, &hmac_len);
+                  key,
+                  key_len,
+                  challenge_decoded,
+                  challenge_decoded_len,
+                  hmac,
+                  &hmac_len);
   free(challenge_decoded);
   if(hmac_ret == NULL){
     return -1;
@@ -2135,9 +2157,9 @@ smtp_set_read_timeout(struct smtp *const smtp,
  * @param[in] smtp                SMTP client context.
  * @param[in] server              Server name or IP address.
  * @param[in] connection_security See @ref smtp_connection_security.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_initiate_handshake(struct smtp *const smtp,
                         const char *const server,
                         enum smtp_connection_security connection_security){
@@ -2220,6 +2242,7 @@ smtp_date_rfc_2822(char *const date){
   struct tm tm_local;
   struct tm tm_utc;
   long offset_utc;
+  double diff_local_utc;
   int rc;
 
   const char weekday_abbreviation[7][4] = {
@@ -2277,7 +2300,8 @@ smtp_date_rfc_2822(char *const date){
    * For example, PST time zone will have an offset of -800 which will get
    * formatted as -0800 in the sprintf call below.
    */
-  offset_utc = difftime(t_local, t_utc);
+  diff_local_utc = difftime(t_local, t_utc);
+  offset_utc = (long)diff_local_utc;
   offset_utc = offset_utc / 60 / 60 * 100;
 
   rc = sprintf(date,
@@ -2322,9 +2346,12 @@ smtp_date_rfc_2822(char *const date){
 static void
 smtp_gen_mime_boundary(char *const boundary){
   size_t i;
+  unsigned int seed;
+
+  seed = (unsigned int)time(NULL);
+  srand(seed);
 
   strcpy(boundary, "mime");
-  srand(time(NULL));
   for(i = 4; i < SMTP_MIME_BOUNDARY_LEN - 1; i++){
     /* Modulo bias okay since we only need to prevent accidental collision. */
     boundary[i] = rand() % 26 + 'A';
@@ -2338,9 +2365,9 @@ smtp_gen_mime_boundary(char *const boundary){
  * @param[in] smtp     SMTP client context.
  * @param[in] boundary MIME boundary text.
  * @param[in] body     Email body text.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_print_mime_header_and_body(struct smtp *const smtp,
                                 const char *const boundary,
                                 const char *const body){
@@ -2402,10 +2429,10 @@ smtp_print_mime_header_and_body(struct smtp *const smtp,
  *
  * @param[in] smtp       SMTP client context.
  * @param[in] boundary   MIME boundary text.
- * @param[in] attachment @ref smtp_attachment.
- * @return @ref smtp_status_code.
+ * @param[in] attachment See @ref smtp_attachment.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_print_mime_attachment(struct smtp *const smtp,
                            const char *const boundary,
                            const struct smtp_attachment *const attachment){
@@ -2462,7 +2489,7 @@ smtp_print_mime_attachment(struct smtp *const smtp,
  * @param[in] boundary MIME boundary text.
  * @return See @ref smtp_status_code and @ref smtp_puts.
  */
-static int
+static enum smtp_status_code
 smtp_print_mime_end(struct smtp *const smtp,
                     const char *const boundary){
   char *concat;
@@ -2481,9 +2508,9 @@ smtp_print_mime_end(struct smtp *const smtp,
  *
  * @param[in] smtp SMTP client context.
  * @param[in] body Null-terminated string to send in the email body.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_print_mime_email(struct smtp *const smtp,
                       const char *const body){
   char boundary[SMTP_MIME_BOUNDARY_LEN];
@@ -2517,9 +2544,9 @@ smtp_print_mime_email(struct smtp *const smtp,
  *
  * @param[in] smtp   SMTP client context.
  * @param[in] header See @ref smtp_header.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_print_header(struct smtp *const smtp,
                   const struct smtp_header *const header){
   size_t key_len;
@@ -2562,14 +2589,14 @@ smtp_print_header(struct smtp *const smtp,
  *
  * The following example shows what the final header might look like when
  * the client sends an email to two CC addresses:
- * Cc: mail1@example.com, mail2@example.com
+ * Cc: mail1\@example.com, mail2\@example.com
  *
  * @param[in] smtp         SMTP client context.
- * @param[in] address_type @ref smtp_address_type.
+ * @param[in] address_type See @ref smtp_address_type.
  * @param[in] key          Header key value, for example, To From Cc.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_append_address_to_header(struct smtp *const smtp,
                               enum smtp_address_type address_type,
                               const char *const key){
@@ -2624,7 +2651,7 @@ smtp_append_address_to_header(struct smtp *const smtp,
       concat = smtp_stpcpy(concat, address->email);
       concat = smtp_stpcpy(concat, ">");
       num_address_in_header += 1;
-      concat_len = concat - header_value;
+      concat_len = (size_t)(concat - header_value);
     }
   }
 
@@ -2639,15 +2666,15 @@ smtp_append_address_to_header(struct smtp *const smtp,
  * Send envelope MAIL FROM or RCPT TO header address.
  *
  * Examples:
- * MAIL FROM:<mail@example.com>
- * RCPT TO:<mail@example.com>
+ * MAIL FROM:<mail\@example.com>
+ * RCPT TO:<mail\@example.com>
  *
  * @param[in] smtp    SMTP client context.
  * @param[in] header  Either "MAIL FROM" or "RCPT TO".
- * @param[in] address @ref smtp_address -> email field.
- * @return @ref smtp_status_code.
+ * @param[in] address See @ref smtp_address -> email field.
+ * @return See @ref smtp_status_code.
  */
-static int
+static enum smtp_status_code
 smtp_mail_envelope_header(struct smtp *const smtp,
                           const char *const header,
                           const struct smtp_address *const address){
@@ -2760,7 +2787,7 @@ smtp_header_exists(const struct smtp *const smtp,
  */
 SMTP_LINKAGE int
 smtp_header_key_validate(const char *const key){
-  unsigned c;
+  unsigned char uc;
   size_t i;
   size_t keylen;
 
@@ -2770,8 +2797,8 @@ smtp_header_key_validate(const char *const key){
   }
 
   for(i = 0; i < keylen; i++){
-    c = key[i];
-    if(c <= ' ' || c > 126 || c == ':'){
+    uc = (unsigned char)key[i];
+    if(uc <= ' ' || uc > 126 || uc == ':'){
       return -1;
     }
   }
@@ -2791,13 +2818,13 @@ smtp_header_key_validate(const char *const key){
 SMTP_LINKAGE int
 smtp_header_value_validate(const char *const value){
   size_t i;
-  unsigned char c;
+  unsigned char uc;
 
   for(i = 0; value[i]; i++){
-    c = value[i];
-    if((c < ' ' || c > 126) &&
-        c != '\t' &&
-        c < 0x80){ /* Allow UTF-8 byte sequence. */
+    uc = (unsigned char)value[i];
+    if((uc < ' ' || uc > 126) &&
+        uc != '\t' &&
+        uc < 0x80){ /* Allow UTF-8 byte sequence. */
       return -1;
     }
   }
@@ -2817,12 +2844,12 @@ smtp_header_value_validate(const char *const value){
 SMTP_LINKAGE int
 smtp_address_validate_email(const char *const email){
   size_t i;
-  unsigned char c;
+  unsigned char uc;
 
   for(i = 0; email[i]; i++){
-    c = email[i];
-    if(c <= ' ' || c == 127 ||
-       c == '<' || c == '>'){
+    uc = (unsigned char)email[i];
+    if(uc <= ' ' || uc == 127 ||
+       uc == '<' || uc == '>'){
       return -1;
     }
   }
@@ -2842,11 +2869,11 @@ smtp_address_validate_email(const char *const email){
 SMTP_LINKAGE int
 smtp_address_validate_name(const char *const name){
   size_t i;
-  unsigned char c;
+  unsigned char uc;
 
   for(i = 0; name[i]; i++){
-    c = name[i];
-    if(c < ' ' || c == 127 || c == '\"'){
+    uc = (unsigned char)name[i];
+    if(uc < ' ' || uc == 127 || uc == '\"'){
       return -1;
     }
   }
@@ -2866,12 +2893,12 @@ smtp_address_validate_name(const char *const name){
 SMTP_LINKAGE int
 smtp_attachment_validate_name(const char *const name){
   size_t i;
-  unsigned c;
+  unsigned char uc;
 
   for(i = 0; name[i]; i++){
-    c = name[i];
-    if(c < ' ' || c == 127 ||
-       c == '\'' || c == '\"'){
+    uc = (unsigned char)name[i];
+    if(uc < ' ' || uc == 127 ||
+       uc == '\'' || uc == '\"'){
       return -1;
     }
   }
@@ -2890,18 +2917,20 @@ smtp_attachment_validate_name(const char *const name){
  * error codes when calling the other header functions because the
  * caller will always get a valid SMTP structure returned.
  */
-static struct smtp smtp_error = {
+static struct smtp
+g_smtp_error = {
   SMTP_FLAG_INVALID_MEMORY, /* flags                        */
   0,                        /* sock                         */
   {                         /* gdfd                         */
     NULL,                   /* _buf                         */
     0,                      /* _bufsz                       */
     0,                      /* _buf_len                     */
-    0,                      /* delim                        */
     NULL,                   /* line                         */
     0,                      /* line_len                     */
     NULL,                   /* getdelimfd_read              */
-    NULL                    /* user_data                    */
+    NULL,                   /* user_data                    */
+    0,                      /* delim                        */
+    {0}                     /* pad                          */
   },                        /* gdfd                         */
   NULL,                     /* header_list                  */
   0,                        /* num_headers                  */
@@ -2909,8 +2938,8 @@ static struct smtp smtp_error = {
   0,                        /* num_address                  */
   NULL,                     /* attachment_list              */
   0,                        /* num_attachment               */
-  SMTP_STATUS_NOMEM,        /* smtp_status_code status_code */
   0,                        /* timeout_sec                  */
+  SMTP_STATUS_NOMEM,        /* smtp_status_code status_code */
   0,                        /* tls_on                       */
   NULL                      /* cafile                       */
 #ifdef SMTP_OPENSSL
@@ -2950,7 +2979,7 @@ static struct smtp smtp_error = {
  *                                 allocation fails. When finished, the caller
  *                                 must free this context using
  *                                 @ref smtp_close.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_open(const char *const server,
@@ -2962,7 +2991,7 @@ smtp_open(const char *const server,
   struct smtp *snew;
 
   if((snew = calloc(1, sizeof(**smtp))) == NULL){
-    *smtp = &smtp_error;
+    *smtp = &g_smtp_error;
     return smtp_status_code_get(*smtp);
   }
   *smtp = snew;
@@ -2999,7 +3028,7 @@ smtp_open(const char *const server,
  * @param[in] auth_method See @ref smtp_authentication_method.
  * @param[in] user        Server authentication user name.
  * @param[in] pass        Server authentication user password.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_auth(struct smtp *const smtp,
@@ -3012,25 +3041,22 @@ smtp_auth(struct smtp *const smtp,
     return smtp->status_code;
   }
 
-  switch(auth_method){
-    case SMTP_AUTH_PLAIN:
-      auth_rc = smtp_auth_plain(smtp, user, pass);
-      break;
-    case SMTP_AUTH_LOGIN:
-      auth_rc = smtp_auth_login(smtp, user, pass);
-      break;
-
+  if(auth_method == SMTP_AUTH_PLAIN){
+    auth_rc = smtp_auth_plain(smtp, user, pass);
+  }
+  else if(auth_method == SMTP_AUTH_LOGIN){
+    auth_rc = smtp_auth_login(smtp, user, pass);
+  }
 #ifdef SMTP_OPENSSL
-    case SMTP_AUTH_CRAM_MD5:
-      auth_rc = smtp_auth_cram_md5(smtp, user, pass);
-      break;
+  else if(auth_method == SMTP_AUTH_CRAM_MD5){
+    auth_rc = smtp_auth_cram_md5(smtp, user, pass);
+  }
 #endif /* SMTP_OPENSSL */
-
-    case SMTP_AUTH_NONE:
-      auth_rc = 0;
-      break;
-    default:
-      return smtp_status_code_set(smtp, SMTP_STATUS_PARAM);
+  else if(auth_method == SMTP_AUTH_NONE){
+    auth_rc = 0;
+  }
+  else{
+    return smtp_status_code_set(smtp, SMTP_STATUS_PARAM);
   }
 
   if(auth_rc < 0){
@@ -3049,7 +3075,7 @@ smtp_auth(struct smtp *const smtp,
  *
  * @param[in] smtp SMTP client context.
  * @param[in] body Null-terminated string to send in the email body.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_mail(struct smtp *const smtp,
@@ -3162,7 +3188,7 @@ smtp_mail(struct smtp *const smtp,
  * SMTP context.
  *
  * @param[in] smtp SMTP client context.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_close(struct smtp *smtp){
@@ -3217,7 +3243,7 @@ smtp_close(struct smtp *smtp){
  * Get the current status/error code described in @ref smtp_status_code.
  *
  * @param[in] smtp SMTP client context.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_status_code_get(const struct smtp *const smtp){
@@ -3235,7 +3261,7 @@ smtp_status_code_get(const struct smtp *const smtp){
  *
  * @param[in] smtp        SMTP client context.
  * @param[in] status_code See @ref smtp_status_code.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_status_code_set(struct smtp *const smtp,
@@ -3303,7 +3329,7 @@ smtp_status_code_errstr(enum smtp_status_code status_code){
  * @param[in] value Value for new header. It must consist only of printable
  *                  US-ASCII, space, or horizontal tab. If set to NULL,
  *                  this will prevent the header from printing out.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_header_add(struct smtp *const smtp,
@@ -3387,7 +3413,7 @@ void smtp_header_clear_all(struct smtp *const smtp){
  *                  printable characters, excluding the quote characters. If
  *                  set to NULL or empty string, no name will get associated
  *                  with this email.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_address_add(struct smtp *const smtp,
@@ -3465,7 +3491,7 @@ void smtp_address_clear_all(struct smtp *const smtp){
  * @param[in] smtp SMTP client context.
  * @param[in] name Filename of the attachment shown to recipients.
  * @param[in] path Path of file location to read from.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_attachment_add_path(struct smtp *const smtp,
@@ -3498,7 +3524,7 @@ smtp_attachment_add_path(struct smtp *const smtp,
  * @param[in] smtp SMTP client context.
  * @param[in] name Filename of the attachment shown to recipients.
  * @param[in] fp   File pointer already opened by the caller.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_attachment_add_fp(struct smtp *const smtp,
@@ -3537,13 +3563,13 @@ smtp_attachment_add_fp(struct smtp *const smtp,
  * @param[in] data   Raw attachment data stored in memory.
  * @param[in] datasz Number of bytes in @p data, or -1 if data
  *                   null-terminated.
- * @return @ref smtp_status_code.
+ * @return See @ref smtp_status_code.
  */
 enum smtp_status_code
 smtp_attachment_add_mem(struct smtp *const smtp,
                         const char *const name,
                         const void *const data,
-                        long datasz){
+                        size_t datasz){
   size_t num_attachment_inc;
   struct smtp_attachment *new_attachment_list;
   struct smtp_attachment *new_attachment;
@@ -3557,7 +3583,7 @@ smtp_attachment_add_mem(struct smtp *const smtp,
     return smtp_status_code_set(smtp, SMTP_STATUS_PARAM);
   }
 
-  if(datasz < 0){
+  if(datasz == SIZE_MAX){
     datasz = strlen(data);
   }
 
diff --git a/src/smtp.h b/src/smtp.h
index e9d3cf1..51e6bd9 100644
--- a/src/smtp.h
+++ b/src/smtp.h
@@ -141,9 +141,9 @@ enum smtp_connection_security{
   /**
    * Use TLS when initially connecting to server.
    *
-   * @deprecated SMTP clients should not use this connection type unless
-   *             connecting to a legacy SMTP server which requires it.
-   *             Instead, use @ref SMTP_SECURITY_STARTTLS if possible.
+   * SMTP clients should not use this connection type unless
+   * connecting to a legacy SMTP server which requires it.
+   * Instead, use @ref SMTP_SECURITY_STARTTLS if possible.
    */
   SMTP_SECURITY_TLS,
 #endif /* SMTP_OPENSSL */
@@ -271,7 +271,7 @@ enum smtp_status_code
 smtp_attachment_add_mem(struct smtp *const smtp,
                         const char *const name,
                         const void *const data,
-                        long datasz);
+                        size_t datasz);
 
 void smtp_attachment_clear_all(struct smtp *const smtp);
 
@@ -391,11 +391,6 @@ struct str_getdelimfd{
   size_t _buf_len;
 
   /**
-   * Character delimiter used for determining line separation.
-   */
-  int delim;
-
-  /**
    * Current line containing the text up to the delimiter.
    */
   char *line;
@@ -422,6 +417,16 @@ struct str_getdelimfd{
    * User data which gets sent to the read handler function.
    */
   void *user_data;
+
+  /**
+   * Character delimiter used for determining line separation.
+   */
+  int delim;
+
+  /**
+   * Padding structure to align.
+   */
+  char pad[4];
 };
 
 #endif /* SMTP_INTERNAL_DEFINE */
diff --git a/test/seams.c b/test/seams.c
index 508836b..eeeb15a 100644
--- a/test/seams.c
+++ b/test/seams.c
@@ -10,13 +10,6 @@
  *
  * This software has been placed into the public domain using CC0.
  */
-
-/**
- * Need to define this on some POSIX systems in order to get access to the
- * getaddrinfo and localtime_r functions.
- */
-#define _POSIX_C_SOURCE 200112L
-
 #include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
@@ -357,7 +350,7 @@ smtp_test_seam_connect(int socket,
 unsigned long
 smtp_test_seam_err_peek_error(void){
   if(smtp_test_seam_dec_err_ctr(&g_smtp_test_err_err_peek_error_ctr)){
-    return -1;
+    return 1;
   }
   return ERR_peek_error();
 }
@@ -429,7 +422,7 @@ smtp_test_seam_hmac(const EVP_MD *evp_md,
                     const void *key,
                     int key_len,
                     const unsigned char *d,
-                    int n,
+                    size_t n,
                     unsigned char *md,
                     unsigned int *md_len){
   if(smtp_test_seam_dec_err_ctr(&g_smtp_test_err_hmac_ctr)){
@@ -529,9 +522,9 @@ smtp_test_seam_recv(int socket,
     }
     if(*g_smtp_test_err_recv_bytes){
       bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
-      assert(bytes_inject_len < length);
+      assert(bytes_inject_len < length && bytes_inject_len < LONG_MAX);
       memcpy(buffer, g_smtp_test_err_recv_bytes, bytes_inject_len);
-      return bytes_inject_len;
+      return (long)bytes_inject_len;
     }
     errno = EBADF;
     return -1;
@@ -578,7 +571,7 @@ smtp_test_seam_select(int nfds,
  * @retval >=0 Number of bytes sent.
  * @retval  -1 Failed to send bytes over the network.
  */
-long
+ssize_t
 smtp_test_seam_send(int socket,
                     const void *buffer,
                     size_t length,
@@ -738,9 +731,9 @@ smtp_test_seam_ssl_read(SSL *ssl,
   if(smtp_test_seam_dec_err_ctr(&g_smtp_test_err_ssl_read_ctr)){
     if(*g_smtp_test_err_recv_bytes){
       bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
-      assert(bytes_inject_len < (size_t)num);
+      assert(bytes_inject_len < (size_t)num && bytes_inject_len < INT_MAX);
       memcpy(buf, g_smtp_test_err_recv_bytes, bytes_inject_len);
-      return bytes_inject_len;
+      return (int)bytes_inject_len;
     }
     return -1;
   }
diff --git a/test/test.c b/test/test.c
index 1b3d7cd..f0bd51f 100644
--- a/test/test.c
+++ b/test/test.c
@@ -12,12 +12,6 @@
  *
  * This software has been placed into the public domain using CC0.
  */
-
-/**
- * This POSIX declaration required for the setenv() function.
- */
-#define _POSIX_C_SOURCE 200112L
-
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -94,7 +88,9 @@
  * These default flags will get used for most test connections with the
  * SMTP server.
  */
-#define SMTP_TEST_DEFAULT_FLAGS               (SMTP_DEBUG | SMTP_NO_CERT_VERIFY)
+#define SMTP_TEST_DEFAULT_FLAGS               (enum smtp_flag)(  \
+                                              SMTP_DEBUG |       \
+                                              SMTP_NO_CERT_VERIFY)
 
 /**
  * Use the default certificate path for OpenSSL.
@@ -307,18 +303,18 @@ smtp_str_list_free(struct smtp_str_list *const list){
  *                       containing the rest of the string. A value of 0 has
  *                       the same meaning as 1. A negative value will cut off
  *                       the last @p limit strings from the result.
- * @param[out] slist
+ * @param[out] slist     See @ref smtp_str_list.
  * @retval  0 Successfully split the string and stored the results into
  *            @p slist.
  * @retval -1 Memory allocation failure.
  */
 static int
 smtp_str_split(const char *const s,
-               long slen,
+               size_t slen,
                const char *const delimiter,
                int limit,
                struct smtp_str_list *slist){
-  int i;
+  size_t i;
   size_t i1;
   size_t i2;
   size_t delimiter_len;
@@ -327,15 +323,16 @@ smtp_str_split(const char *const s,
   memset(slist, 0, sizeof(*slist));
   delimiter_len = strlen(delimiter);
 
-  if(slen < 0){
+  if(slen == SIZE_MAX){
     slen = strlen(s);
   }
 
   split_idx = 0;
 
-  for(i1 = 0, i2 = 0; i2 < (size_t)slen; i2++){
+  i1 = 0;
+  for(i2 = 0; i2 < slen; i2++){
     if(limit > 0 && limit - 1 <= split_idx){
-      if(smtp_str_list_append(slist, &s[i1], -1) < 0){
+      if(smtp_str_list_append(slist, &s[i1], SIZE_MAX) < 0){
         smtp_str_list_free(slist);
         return -1;
       }
@@ -364,7 +361,7 @@ smtp_str_split(const char *const s,
   }
 
   if(limit < 0){
-    for(i = 0; i < abs(limit); i++){
+    for(i = 0; i < (size_t)abs(limit); i++){
       free(slist->slist[slist->n - i - 1]);
     }
     slist->n -= i;
@@ -385,12 +382,12 @@ smtp_str_split(const char *const s,
 static size_t
 smtp_ffile_put_contents(FILE *stream,
                         const void *const data,
-                        long datasz){
-  long bytes_written;
+                        size_t datasz){
+  size_t bytes_written;
 
   bytes_written = 0;
 
-  if(datasz < 0){
+  if(datasz == SIZE_MAX){
     bytes_written = strlen(data);
     if(fputs(data, stream) == EOF){
       bytes_written = 0;
@@ -423,7 +420,7 @@ smtp_ffile_put_contents(FILE *stream,
 static size_t
 smtp_file_put_contents(const char *const filename,
                        const void *const data,
-                       long datasz,
+                       size_t datasz,
                        int flags){
   FILE *fp;
   size_t bytes_written;
@@ -508,8 +505,8 @@ smtp_unit_test_all_si(void){
   smtp_unit_test_si_size_t(smtp_si_add_size_t, 0, 1, &result, 1, 0);
   smtp_unit_test_si_size_t(smtp_si_add_size_t, 1, 0, &result, 1, 0);
   smtp_unit_test_si_size_t(smtp_si_add_size_t, 1, 1, &result, 2, 0);
-  smtp_unit_test_si_size_t(smtp_si_add_size_t, 1, 1, NULL, -1, 0);
-  smtp_unit_test_si_size_t(smtp_si_add_size_t, SIZE_MAX, 1, NULL, -1, 1);
+  smtp_unit_test_si_size_t(smtp_si_add_size_t, 1, 1, NULL, SIZE_MAX, 0);
+  smtp_unit_test_si_size_t(smtp_si_add_size_t, SIZE_MAX, 1, NULL, SIZE_MAX, 1);
   smtp_unit_test_si_size_t(smtp_si_add_size_t, SIZE_MAX, 0, &result, SIZE_MAX, 0);
   smtp_unit_test_si_size_t(smtp_si_add_size_t, SIZE_MAX, 1, &result, 0, 1);
   smtp_unit_test_si_size_t(smtp_si_add_size_t, SIZE_MAX - 1, 2, &result, 0, 1);
@@ -527,16 +524,16 @@ smtp_unit_test_all_si(void){
   smtp_unit_test_si_size_t(smtp_si_sub_size_t, 1, 0, &result, 1, 0);
   smtp_unit_test_si_size_t(smtp_si_sub_size_t, 1, 1, &result, 0, 0);
   smtp_unit_test_si_size_t(smtp_si_sub_size_t, 2, 3, &result, SIZE_MAX, 1);
-  smtp_unit_test_si_size_t(smtp_si_sub_size_t, 2, 1, NULL, -1, 0);
-  smtp_unit_test_si_size_t(smtp_si_sub_size_t, 1, 2, NULL, -1, 1);
+  smtp_unit_test_si_size_t(smtp_si_sub_size_t, 2, 1, NULL, SIZE_MAX, 0);
+  smtp_unit_test_si_size_t(smtp_si_sub_size_t, 1, 2, NULL, SIZE_MAX, 1);
 
   /* multiply */
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, 0, 0, &result, 0, 0);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, 0, 1, &result, 0, 0);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, 1, 0, &result, 0, 0);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, 1, 1, &result, 1, 0);
-  smtp_unit_test_si_size_t(smtp_si_mul_size_t, 1, 1, NULL, -1, 0);
-  smtp_unit_test_si_size_t(smtp_si_mul_size_t, SIZE_MAX, 2, NULL, -1, 1);
+  smtp_unit_test_si_size_t(smtp_si_mul_size_t, 1, 1, NULL, SIZE_MAX, 0);
+  smtp_unit_test_si_size_t(smtp_si_mul_size_t, SIZE_MAX, 2, NULL, SIZE_MAX, 1);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, 100, 12, &result, 1200, 0);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t, SIZE_MAX, 1, &result, SIZE_MAX, 0);
   smtp_unit_test_si_size_t(smtp_si_mul_size_t,
@@ -557,9 +554,9 @@ smtp_unit_test_all_si(void){
 static void
 smtp_unit_test_base64_decode(const char *const buf,
                              const char *const expect_str,
-                             long expect_str_len){
+                             size_t expect_str_len){
   unsigned char *decode;
-  long str_len;
+  size_t str_len;
 
   str_len = smtp_base64_decode(buf, &decode);
   if(expect_str){
@@ -590,17 +587,17 @@ smtp_unit_test_all_base64_decode(void){
                                26);
 
   /* invalid inputs */
-  smtp_unit_test_base64_decode("AB"     , NULL, -1);
-  smtp_unit_test_base64_decode("^^^^"   , NULL, -1);
-  smtp_unit_test_base64_decode("^^^\xFF", NULL, -1);
+  smtp_unit_test_base64_decode("AB"     , NULL, SIZE_MAX);
+  smtp_unit_test_base64_decode("^^^^"   , NULL, SIZE_MAX);
+  smtp_unit_test_base64_decode("^^^\xFF", NULL, SIZE_MAX);
 
   /* Wrap when calculating the buffer length. */
   g_smtp_test_err_si_add_size_t_ctr = 0;
-  smtp_unit_test_base64_decode("YQ=="    , NULL, -1);
+  smtp_unit_test_base64_decode("YQ=="    , NULL, SIZE_MAX);
   g_smtp_test_err_si_add_size_t_ctr = -1;
 
   g_smtp_test_err_calloc_ctr = 0;
-  smtp_unit_test_base64_decode("", NULL, -1);
+  smtp_unit_test_base64_decode("", NULL, SIZE_MAX);
   g_smtp_test_err_calloc_ctr = -1;
 }
 
@@ -632,15 +629,15 @@ smtp_unit_test_base64_encode(const char *const buf,
  */
 static void
 smtp_unit_test_all_base64_encode(void){
-  smtp_unit_test_base64_encode(""     , -1, "");
-  smtp_unit_test_base64_encode("a"    , -1, "YQ==");
-  smtp_unit_test_base64_encode("aa"   , -1, "YWE=");
-  smtp_unit_test_base64_encode("aaa"  , -1, "YWFh");
-  smtp_unit_test_base64_encode("aaaa" , -1, "YWFhYQ==");
-  smtp_unit_test_base64_encode("aaaaa", -1, "YWFhYWE=");
-  smtp_unit_test_base64_encode("12345", -1, "MTIzNDU=");
+  smtp_unit_test_base64_encode(""     , SIZE_MAX, "");
+  smtp_unit_test_base64_encode("a"    , SIZE_MAX, "YQ==");
+  smtp_unit_test_base64_encode("aa"   , SIZE_MAX, "YWE=");
+  smtp_unit_test_base64_encode("aaa"  , SIZE_MAX, "YWFh");
+  smtp_unit_test_base64_encode("aaaa" , SIZE_MAX, "YWFhYQ==");
+  smtp_unit_test_base64_encode("aaaaa", SIZE_MAX, "YWFhYWE=");
+  smtp_unit_test_base64_encode("12345", SIZE_MAX, "MTIzNDU=");
   smtp_unit_test_base64_encode(STR_ALPHABET_LOWERCASE,
-                               -1,
+                               SIZE_MAX,
                                "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=");
 
   /* binary data */
@@ -650,13 +647,13 @@ smtp_unit_test_all_base64_encode(void){
   /* Value would wrap */
   g_smtp_test_strlen_custom_ret = 1;
   g_smtp_test_strlen_ret_value = SIZE_MAX - 1;
-  smtp_unit_test_base64_encode("a", -1, NULL);
+  smtp_unit_test_base64_encode("a", SIZE_MAX, NULL);
   g_smtp_test_strlen_custom_ret = 0;
   g_smtp_test_strlen_ret_value = 0;
 
   /* calloc */
   g_smtp_test_err_calloc_ctr = 0;
-  smtp_unit_test_base64_encode("", -1, NULL);
+  smtp_unit_test_base64_encode("", SIZE_MAX, NULL);
   g_smtp_test_err_calloc_ctr = -1;
 }
 
@@ -891,7 +888,7 @@ smtp_unit_test_str_replace(const char *const search,
  */
 static void
 smtp_unit_test_all_str_replace(void){
-  size_t i;
+  int i;
 
   smtp_unit_test_str_replace("", "", "", "");
   smtp_unit_test_str_replace("a", "b", "", "");
@@ -1021,8 +1018,8 @@ smtp_unit_test_all_strnlen_utf8(void){
   smtp_unit_test_strnlen_utf8("𠜎", 3, 4);
 
   /* Invalid UTF-8 sequences. */
-  smtp_unit_test_strnlen_utf8("\xBF", 3, -1);
-  smtp_unit_test_strnlen_utf8("\xC0", 3, -1);
+  smtp_unit_test_strnlen_utf8("\xBF", 3, SIZE_MAX);
+  smtp_unit_test_strnlen_utf8("\xC0", 3, SIZE_MAX);
 }
 
 /**
@@ -1182,7 +1179,7 @@ smtp_unit_test_fold_whitespace(const char *const s,
  */
 static void
 smtp_unit_test_all_fold_whitespace(void){
-  size_t i;
+  int i;
 
   smtp_unit_test_fold_whitespace("Subject: Email Test",
                                  5,
@@ -1276,7 +1273,7 @@ smtp_unit_test_chunk_split(const char *const s,
  */
 static void
 smtp_unit_test_all_chunk_split(void){
-  size_t i;
+  int i;
 
   smtp_unit_test_chunk_split("", 0, "", NULL);
   smtp_unit_test_chunk_split("a", 0, "a", NULL);
@@ -1379,7 +1376,7 @@ smtp_unit_test_all_file_get_contents(void){
   smtp_unit_test_file_get_contents(test_str, strlen(test_str), test_str);
 
   test_str = "test";
-  smtp_unit_test_file_get_contents(test_str, -1, test_str);
+  smtp_unit_test_file_get_contents(test_str, SIZE_MAX, test_str);
 
   test_str = STR_ALPHABET_LOWERCASE;
   smtp_unit_test_file_get_contents(test_str, strlen(test_str), test_str);
@@ -1464,11 +1461,7 @@ smtp_unit_test_all_parse_cmd_line(void){
                                 0,
                                 "text");
   smtp_unit_test_parse_cmd_line("-22 text",
-                                -22,
-                                0,
-                                "text");
-  smtp_unit_test_parse_cmd_line("-22 text",
-                                -22,
+                                SMTP_INTERNAL_ERROR,
                                 0,
                                 "text");
   smtp_unit_test_parse_cmd_line("220 ready",
@@ -1632,9 +1625,9 @@ smtp_unit_test_all_smtp_status_code_errstr(void){
                                          "Success");
   smtp_unit_test_smtp_status_code_errstr(SMTP_STATUS_NOMEM,
                                          "Memory allocation failed");
-  smtp_unit_test_smtp_status_code_errstr(-1,
+  smtp_unit_test_smtp_status_code_errstr((enum smtp_status_code)-1,
                                          "Unknown error");
-  smtp_unit_test_smtp_status_code_errstr(99,
+  smtp_unit_test_smtp_status_code_errstr((enum smtp_status_code)99,
                                          "Unknown error");
 }
 
@@ -1676,7 +1669,7 @@ smtp_unit_test_getdelimfd_fp(struct str_getdelimfd *const gdfd,
   if(g_smtp_test_getdelimfd_fp_fail){
     return -1;
   }
-  return bytes_read;
+  return (long)bytes_read;
 }
 
 /**
@@ -1757,7 +1750,7 @@ smtp_unit_test_str_getdelimfd(const char *const input_string,
 /**
  * Test harness for @ref smtp_str_getdelimfd_set_line_and_buf.
  *
- * @param[in] gdfd          @ref str_getdelimfd.
+ * @param[in] gdfd          See @ref str_getdelimfd.
  * @param[in] copy_len      Number of bytes to copy to the internal line buffer.
  * @param[in] expect_result Expected result code (0 or -1) from
  *                          @ref smtp_str_getdelimfd_set_line_and_buf.
@@ -1780,7 +1773,7 @@ smtp_unit_test_all_str_getdelimfd(void){
   const char *s;
   struct str_getdelimfd gdfd;
   char test_str[] = "test";
-  size_t i;
+  int i;
 
   s = "";
   smtp_unit_test_str_getdelimfd(s,
@@ -2169,7 +2162,7 @@ smtp_test_config_load_from_file(const char *const config_path,
  */
 static void
 test_smtp_open_default(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -2200,7 +2193,7 @@ test_smtp_open_default(struct smtp_test_config *const config){
   rc = smtp_attachment_add_mem(config->smtp,
                                "test.txt",
                                "test attachment",
-                               -1);
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_OK);
 }
 
@@ -2211,7 +2204,7 @@ test_smtp_open_default(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_status_code_get(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -2257,7 +2250,7 @@ smtp_func_test_send_email(struct smtp_test_config *const config,
                           const char *const cafile,
                           const char *const subject,
                           const char *const body){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  port,
@@ -2417,8 +2410,8 @@ static void
 smtp_func_test_attachment_path(struct smtp_test_config *const config,
                                const char *const name,
                                const char *const path,
-                               int expect_rc){
-  int rc;
+                               enum smtp_status_code expect_rc){
+  enum smtp_status_code rc;
 
   strcpy(config->subject, "SMTP Test: Attachment (file path)");
   strcpy(config->body, "This email should contain a pdf attachment");
@@ -2475,9 +2468,10 @@ static void
 smtp_func_test_attachment_fp(struct smtp_test_config *const config,
                              const char *const name,
                              const char *const path,
-                             int expect_rc){
-  int rc;
+                             enum smtp_status_code expect_rc){
+  enum smtp_status_code rc;
   FILE *fp;
+  int fp_rc;
 
   strcpy(config->subject, "SMTP Test: Attachment (fp)");
   strcpy(config->body, "This email should contain a pdf attachment");
@@ -2517,8 +2511,8 @@ smtp_func_test_attachment_fp(struct smtp_test_config *const config,
   rc = smtp_close(config->smtp);
   assert(rc == expect_rc);
 
-  rc = fclose(fp);
-  assert(rc == 0);
+  fp_rc = fclose(fp);
+  assert(fp_rc == 0);
 }
 
 /**
@@ -2533,7 +2527,7 @@ smtp_func_test_attachment_mem(struct smtp_test_config *const config,
   size_t i;
   char attachment_name[SMTP_MAX_ATTACHMENT_NAME_LEN];
   char attachment_data[100];
-  int rc;
+  enum smtp_status_code rc;
 
   sprintf(config->subject,
           "SMTP Test: Attachments (%u)",
@@ -2576,7 +2570,7 @@ smtp_func_test_attachment_mem(struct smtp_test_config *const config,
     rc = smtp_attachment_add_mem(config->smtp,
                                  attachment_name,
                                  attachment_data,
-                                 -1);
+                                 SIZE_MAX);
     assert(rc == SMTP_STATUS_OK);
   }
 
@@ -2597,7 +2591,7 @@ smtp_func_test_attachment_mem(struct smtp_test_config *const config,
  */
 static void
 smtp_func_test_attachment_long_text(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
   char *long_text;
 
   /* Send Large attachment attachment with repeated text. */
@@ -2632,7 +2626,7 @@ smtp_func_test_attachment_long_text(struct smtp_test_config *const config){
   rc = smtp_attachment_add_mem(config->smtp,
                                "alphabet-repeat.txt",
                                long_text,
-                               -1);
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_OK);
   free(long_text);
 
@@ -2717,7 +2711,7 @@ smtp_func_test_all_attachments(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_address(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -2884,7 +2878,7 @@ smtp_func_test_all_address(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_names(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
   char *long_name;
 
   rc = smtp_open(config->server,
@@ -3035,7 +3029,7 @@ smtp_func_test_all_names(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_header_custom_date(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3086,7 +3080,7 @@ smtp_func_test_header_custom_date(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_header_null_no_date(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3135,7 +3129,7 @@ smtp_func_test_header_null_no_date(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_header_long(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
   char *long_text;
 
   rc = smtp_open(config->server,
@@ -3202,7 +3196,7 @@ smtp_func_test_all_headers(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_body(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
   char *long_body;
 
   rc = smtp_open(config->server,
@@ -3249,7 +3243,7 @@ smtp_func_test_all_body(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_write(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   g_smtp_test_send_one_byte = 1;
   rc = smtp_open(config->server,
@@ -3271,7 +3265,7 @@ smtp_func_test_all_write(struct smtp_test_config *const config){
  */
 static void
 smtp_func_test_all_nodebug(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3316,7 +3310,7 @@ smtp_func_test_all_nodebug(struct smtp_test_config *const config){
  */
 static void
 test_failure_misc(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   /* Send buffer to large in @ref smtp_write. */
   rc = smtp_open(config->server,
@@ -3352,7 +3346,7 @@ test_failure_misc(struct smtp_test_config *const config){
  */
 static void
 test_failure_open(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   /* Initial memory allocation failure for the SMTP client context. */
   g_smtp_test_err_calloc_ctr = 0;
@@ -3672,7 +3666,7 @@ test_failure_open(struct smtp_test_config *const config){
  */
 static void
 test_failure_address_add(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3758,8 +3752,9 @@ test_failure_address_add(struct smtp_test_config *const config){
  */
 static void
 test_failure_attachment_add(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
   FILE *fp;
+  int fp_rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3772,7 +3767,10 @@ test_failure_attachment_add(struct smtp_test_config *const config){
 
   /* Invalid SMTP status code. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_PARAM);
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_PARAM);
 
 
@@ -3781,27 +3779,36 @@ test_failure_attachment_add(struct smtp_test_config *const config){
   rc = smtp_attachment_add_mem(config->smtp,
                                "\"invalid\"",
                                "test",
-                               -1);
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_PARAM);
 
   /* Wrap when increasing the attachment list size. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
   g_smtp_test_err_si_add_size_t_ctr = 0;
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_NOMEM);
   g_smtp_test_err_si_add_size_t_ctr = -1;
 
   /* Memory allocation failure while increasing the attachment list size. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
   g_smtp_test_err_realloc_ctr = 0;
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_NOMEM);
   g_smtp_test_err_realloc_ctr = -1;
 
   /* Memory allocation failure while using smtp_strdup on file name. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
   g_smtp_test_err_malloc_ctr = 0;
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_NOMEM);
   g_smtp_test_err_malloc_ctr = -1;
 
@@ -3809,14 +3816,20 @@ test_failure_attachment_add(struct smtp_test_config *const config){
   /* Memory allocation failure while using smtp_base64_encode. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
   g_smtp_test_err_calloc_ctr = 0;
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_NOMEM);
   g_smtp_test_err_calloc_ctr = -1;
 
   /* Memory allocation failure when splitting base64 lines into chunks. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
   g_smtp_test_err_calloc_ctr = 1;
-  rc = smtp_attachment_add_mem(config->smtp, "valid", "test", -1);
+  rc = smtp_attachment_add_mem(config->smtp,
+                               "valid",
+                               "test",
+                               SIZE_MAX);
   assert(rc == SMTP_STATUS_NOMEM);
   g_smtp_test_err_calloc_ctr = -1;
 
@@ -3840,8 +3853,8 @@ test_failure_attachment_add(struct smtp_test_config *const config){
   rc = smtp_attachment_add_fp(config->smtp, "test", fp);
   g_smtp_test_err_ferror_ctr = -1;
   assert(rc == SMTP_STATUS_FILE);
-  rc = fclose(fp);
-  assert(rc == 0);
+  fp_rc = fclose(fp);
+  assert(fp_rc == 0);
 
   /* @ref smtp_file_get_contents memory allocation failure. */
   smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
@@ -3867,7 +3880,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
  */
 static void
 test_failure_header_add(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3941,7 +3954,7 @@ test_failure_header_add(struct smtp_test_config *const config){
  */
 static void
 test_failure_status_code_set(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -3951,7 +3964,7 @@ test_failure_status_code_set(struct smtp_test_config *const config){
                  &config->smtp);
   assert(rc == SMTP_STATUS_OK);
 
-  rc = smtp_status_code_set(config->smtp, -1);
+  rc = smtp_status_code_set(config->smtp, (enum smtp_status_code)-1);
   assert(rc == SMTP_STATUS_PARAM);
 
   rc = smtp_status_code_set(config->smtp, SMTP_STATUS__LAST);
@@ -3971,7 +3984,7 @@ test_failure_status_code_set(struct smtp_test_config *const config){
  */
 static void
 test_failure_mail(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   /* Invalid SMTP client context. */
   test_smtp_open_default(config);
@@ -4284,7 +4297,7 @@ test_failure_mail(struct smtp_test_config *const config){
  */
 static void
 test_failure_close(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   /* Failed to send the QUIT command. */
   rc = smtp_open(config->server,
@@ -4340,7 +4353,7 @@ test_failure_close(struct smtp_test_config *const config){
  */
 static void
 test_failure_auth(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   smtp_test_sleep(15);
 
@@ -4359,7 +4372,7 @@ test_failure_auth(struct smtp_test_config *const config){
   /* Invalid authentication method. */
   test_smtp_open_default(config);
   rc = smtp_auth(config->smtp,
-                 -1,
+                 (enum smtp_authentication_method)-1,
                  config->user,
                  config->pass);
   assert(rc == SMTP_STATUS_PARAM);
@@ -4790,7 +4803,7 @@ test_failure_auth(struct smtp_test_config *const config){
  */
 static void
 test_failure_timeout(struct smtp_test_config *const config){
-  int rc;
+  enum smtp_status_code rc;
 
   rc = smtp_open(config->server,
                  config->port,
@@ -4878,7 +4891,7 @@ static void
 smtp_func_test_gmail_attachment(struct smtp_test_config *const config){
   const char *const name = "test.pdf";
   const char *const path = "test/test.pdf";
-  int rc;
+  enum smtp_status_code rc;
 
   strcpy(config->subject, "SMTP Test: GMail Attachment (file path)");
   strcpy(config->body, "This email should contain a pdf attachment");
diff --git a/test/test.h b/test/test.h
index 35b48c5..4d68af7 100644
--- a/test/test.h
+++ b/test/test.h
@@ -62,7 +62,7 @@ smtp_si_mul_size_t(const size_t a,
                    const size_t b,
                    size_t *const result);
 
-long
+size_t
 smtp_base64_decode(const char *const buf,
                    unsigned char **decode);
 
@@ -106,13 +106,13 @@ smtp_str_replace(const char *const search,
             const char *const replace,
             const char *const s);
 
-int
-smtp_utf8_charlen(unsigned char c);
+size_t
+smtp_utf8_charlen(char c);
 
 int
 smtp_str_has_nonascii_utf8(const char *const s);
 
-long
+size_t
 smtp_strnlen_utf8(const char *s,
                   size_t maxlen);
 
@@ -200,7 +200,7 @@ smtp_test_seam_hmac(const EVP_MD *evp_md,
                     const void *key,
                     int key_len,
                     const unsigned char *d,
-                    int n,
+                    size_t n,
                     unsigned char *md,
                     unsigned int *md_len);
 
@@ -232,7 +232,7 @@ smtp_test_seam_select(int nfds,
                       fd_set *errorfds,
                       struct timeval *timeout);
 
-long
+ssize_t
 smtp_test_seam_send(int socket,
                     const void *buffer,
                     size_t length,
@@ -290,14 +290,14 @@ smtp_test_seam_time(time_t *tloc);
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_bio_new_socket_ctr;
+extern int g_smtp_test_err_bio_new_socket_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_bio_should_retry.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_bio_should_retry_ctr;
+extern int g_smtp_test_err_bio_should_retry_ctr;
 
 /**
  * Value to force the BIO_should_retry() function to return.
@@ -306,98 +306,98 @@ int g_smtp_test_err_bio_should_retry_ctr;
  * @ref g_smtp_test_err_bio_should_retry_ctr
  * has a value of 0 and this does not have a value of -1.
  */
-int g_smtp_test_err_bio_should_retry_rc;
+extern int g_smtp_test_err_bio_should_retry_rc;
 
 /**
  * Counter for @ref smtp_test_seam_calloc.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_calloc_ctr;
+extern int g_smtp_test_err_calloc_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_close.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_close_ctr;
+extern int g_smtp_test_err_close_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_connect.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_connect_ctr;
+extern int g_smtp_test_err_connect_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_err_peek_error.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_err_peek_error_ctr;
+extern int g_smtp_test_err_err_peek_error_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_fclose.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_fclose_ctr;
+extern int g_smtp_test_err_fclose_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ferror.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ferror_ctr;
+extern int g_smtp_test_err_ferror_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_gmtime_r.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_gmtime_r_ctr;
+extern int g_smtp_test_err_gmtime_r_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_hmac.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_hmac_ctr;
+extern int g_smtp_test_err_hmac_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_localtime_r.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_localtime_r_ctr;
+extern int g_smtp_test_err_localtime_r_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_malloc.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_malloc_ctr;
+extern int g_smtp_test_err_malloc_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_mktime.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_mktime_ctr;
+extern int g_smtp_test_err_mktime_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_realloc.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_realloc_ctr;
+extern int g_smtp_test_err_realloc_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_recv.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_recv_ctr;
+extern int g_smtp_test_err_recv_ctr;
 
 /**
  * Value to force the recv() function to return.
@@ -406,7 +406,7 @@ int g_smtp_test_err_recv_ctr;
  * @ref g_smtp_test_err_recv_ctr
  * has a value of 0 and this does not have a value of -1.
  */
-int g_smtp_test_err_recv_rc;
+extern int g_smtp_test_err_recv_rc;
 
 /**
  * Set the received bytes in recv() and SSL_read() to this value if it
@@ -417,117 +417,117 @@ int g_smtp_test_err_recv_rc;
  *
  * See @ref test_seams_countdown_global for more details.
  */
-char g_smtp_test_err_recv_bytes[90];
+extern char g_smtp_test_err_recv_bytes[90];
 
 /**
  * Counter for @ref smtp_test_seam_select.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_select_ctr;
+extern int g_smtp_test_err_select_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_send.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_send_ctr;
+extern int g_smtp_test_err_send_ctr;
 
 /**
  * Indicate if we should only send one byte at a time.
  */
-int g_smtp_test_send_one_byte;
+extern int g_smtp_test_send_one_byte;
 
 /**
  * Counter for @ref smtp_si_add_size_t.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_si_add_size_t_ctr;
+extern int g_smtp_test_err_si_add_size_t_ctr;
 
 /**
  * Counter for @ref smtp_si_sub_size_t.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_si_sub_size_t_ctr;
+extern int g_smtp_test_err_si_sub_size_t_ctr;
 
 /**
  * Counter for @ref smtp_si_mul_size_t.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_si_mul_size_t_ctr;
+extern int g_smtp_test_err_si_mul_size_t_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_socket.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_socket_ctr;
+extern int g_smtp_test_err_socket_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_connect.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_connect_ctr;
+extern int g_smtp_test_err_ssl_connect_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_ctx_new.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_ctx_new_ctr;
+extern int g_smtp_test_err_ssl_ctx_new_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_do_handshake.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_do_handshake_ctr;
+extern int g_smtp_test_err_ssl_do_handshake_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_get_peer_certificate.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_get_peer_certificate_ctr;
+extern int g_smtp_test_err_ssl_get_peer_certificate_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_x509_check_host.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_x509_check_host_ctr;
+extern int g_smtp_test_err_x509_check_host_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_new.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_new_ctr;
+extern int g_smtp_test_err_ssl_new_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_read.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_read_ctr;
+extern int g_smtp_test_err_ssl_read_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_ssl_write.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_ssl_write_ctr;
+extern int g_smtp_test_err_ssl_write_ctr;
 
 /**
  * Counter for @ref smtp_test_seam_sprintf.
  *
  * See @ref test_seams_countdown_global for more details.
  */
-int g_smtp_test_err_sprintf_ctr;
+extern int g_smtp_test_err_sprintf_ctr;
 
 /**
  * Value to force the sprintf() function to return.
@@ -535,7 +535,7 @@ int g_smtp_test_err_sprintf_ctr;
  * This value will only get returned if @ref g_smtp_test_err_sprintf_ctr has
  * a value of 0.
  */
-int g_smtp_test_err_sprintf_rc;
+extern int g_smtp_test_err_sprintf_rc;
 
 /**
  * Indicates if the strlen() function should return a test value.
@@ -545,7 +545,7 @@ int g_smtp_test_err_sprintf_rc;
  *   - !0 - The strlen() function will return the value specified in
  *          @ref g_smtp_test_strlen_ret_value.
  */
-int g_smtp_test_strlen_custom_ret;
+extern int g_smtp_test_strlen_custom_ret;
 
 /**
  * Value to force the strlen() function to return.
@@ -553,7 +553,7 @@ int g_smtp_test_strlen_custom_ret;
  * This value will only get returned if @ref g_smtp_test_strlen_custom_ret
  * has been set.
  */
-size_t g_smtp_test_strlen_ret_value;
+extern size_t g_smtp_test_strlen_ret_value;
 
 /**
  * Indicates if the time() function should return a custom value.
@@ -563,7 +563,7 @@ size_t g_smtp_test_strlen_ret_value;
  *   - !0 - The time() function will return the value specified in
  *          @ref g_smtp_test_time_ret_value.
  */
-int g_smtp_test_time_custom_ret;
+extern int g_smtp_test_time_custom_ret;
 
 /**
  * Value to force the time() function to return.
@@ -571,7 +571,7 @@ int g_smtp_test_time_custom_ret;
  * This value will only get returned if @ref g_smtp_test_time_custom_ret has
  * a positive value.
  */
-time_t g_smtp_test_time_ret_value;
+extern time_t g_smtp_test_time_ret_value;
 
 #endif /* SMTP_TEST_H */