summaryrefslogtreecommitdiffstats
path: root/IP2Location-8.0.9-adebc0ef.patch
blob: bb3940aa5f9eb4efe35eb48f73cb5cf32d6ba663 (plain)
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
diff --git a/README.md b/README.md
index 85a3d1f..806b3cd 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,12 @@ For more details, please visit:
 * Use the IPv4 BIN file if you just need to query IPv4 addresses.
 * Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
 
+# NOTES
+If you encountered **error while loading shared libraries** in linux platform, that could be due to the shared library was saved into **usr/local/lib** that might not be the default library path. You can run the below command
+```
+ldconfig /usr/local/lib
+```
+
 # Support
 Email: support@ip2location.com.  
 URL: [https://www.ip2location.com](https://www.ip2location.com)
diff --git a/contrib/IP2Location.spec b/contrib/IP2Location.spec
index 7b76cb8..8fed016 100644
--- a/contrib/IP2Location.spec
+++ b/contrib/IP2Location.spec
@@ -3,12 +3,10 @@
 Name:		IP2Location
 Summary:	C library for mapping IP address to geolocation information
 Version:	%{version}
-Release:	5%{?dist}
-Group:		System Environment/Libraries
+Release:	6%{?dist}
 License:	MIT
 URL:		http://www.ip2location.com/
-Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}.tar.gz
-BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}/%{name}-%{version}.tar.gz
 BuildRequires:	libtool
 
 
@@ -26,7 +24,6 @@ the included downloader.
 
 %package 	devel
 Summary:	Static library and header files for the ip2location library
-Group:		Development/C
 Requires:	%{name} = %{version}-%{release}
 Provides:	%{name}-devel = %{version}-%{release}
 
@@ -51,63 +48,60 @@ perl -pi -e 's/-Wno-unused-result//' configure.ac
 
 %build
 sh ./bootstrap
-autoreconf -fi
+autoreconf -fiv
 
 %configure --disable-static
-make clean
-make %{?_smp_mflags} COPTS="$RPM_OPT_FLAGS"
+%make_build COPTS="$RPM_OPT_FLAGS"
 
 # convert CSV to BIN
 make -C data convert
 
+
 %check
 LD_LIBRARY_PATH=%{buildroot}%{_libdir}:$LD_LIBRARY_PATH make check
 
 
 %install
-rm -rf %{buildroot}
-
-make install DESTDIR=%{buildroot}
+%make_install
 
 # cleanup
 rm -f %{buildroot}%{_libdir}/*.*a
 
 # tools
 install -d %{buildroot}%{_datadir}/%{name}/tools
-cp tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
+install -pm 0755 tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
 
 # database directory
 install -d %{buildroot}%{_datadir}/%{name}/
 
 
-%post -p /sbin/ldconfig
-
-%postun -p /sbin/ldconfig
-
-
-%clean
-rm -rf %{buildroot}
-
 %files
-%defattr(644,root,root,755)
+%license COPYING LICENSE.TXT
 
-%doc AUTHORS ChangeLog COPYING README.md LICENSE.TXT NEWS INSTALL LICENSE.TXT
+%doc AUTHORS ChangeLog README.md NEWS
 
-%attr(755,-,-) %{_libdir}/*.so*
+%{_libdir}/libIP2Location.so.1
+%{_libdir}/libIP2Location.so.1.0.0
 
-%attr(755,-,-) %{_datadir}/%{name}/tools/*
+%{_datadir}/%{name}/tools/
 
 %dir %{_datadir}/%{name}/
 
 
 %files devel
-%defattr(-,root,root)
-%{_includedir}/*
+%{_includedir}/IP2Loc*.h
+%{_libdir}/libIP2Location.so
 
 %doc Developers_Guide.txt
 
 
 %changelog
+* Fri Aug 28 2020 Peter Bieringer <pb@bieringer.de>
+- fix spec file according to BZ#1873302
+
+* Sat Oct  5 2019 Peter Bieringer <pb@bieringer.de> - 8.0.9-5
+- update version to 8.0.9
+
 * Sun Feb 26 2017 Peter Bieringer <pb@bieringer.de> - 8.0.4-5
 - update to 8.0.4
 - add some fixes related to move to github
diff --git a/contrib/IP2Location.spec.in b/contrib/IP2Location.spec.in
index b544e8a..be95898 100644
--- a/contrib/IP2Location.spec.in
+++ b/contrib/IP2Location.spec.in
@@ -3,12 +3,10 @@
 Name:		IP2Location
 Summary:	C library for mapping IP address to geolocation information
 Version:	%{version}
-Release:	5%{?dist}
-Group:		System Environment/Libraries
+Release:	6%{?dist}
 License:	MIT
 URL:		http://www.ip2location.com/
-Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}.tar.gz
-BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}/%{name}-%{version}.tar.gz
 BuildRequires:	libtool
 
 
@@ -26,7 +24,6 @@ the included downloader.
 
 %package 	devel
 Summary:	Static library and header files for the ip2location library
-Group:		Development/C
 Requires:	%{name} = %{version}-%{release}
 Provides:	%{name}-devel = %{version}-%{release}
 
@@ -51,63 +48,60 @@ perl -pi -e 's/-Wno-unused-result//' configure.ac
 
 %build
 sh ./bootstrap
-autoreconf -fi
+autoreconf -fiv
 
 %configure --disable-static
-make clean
-make %{?_smp_mflags} COPTS="$RPM_OPT_FLAGS"
+%make_build COPTS="$RPM_OPT_FLAGS"
 
 # convert CSV to BIN
 make -C data convert
 
+
 %check
 LD_LIBRARY_PATH=%{buildroot}%{_libdir}:$LD_LIBRARY_PATH make check
 
 
 %install
-rm -rf %{buildroot}
-
-make install DESTDIR=%{buildroot}
+%make_install
 
 # cleanup
 rm -f %{buildroot}%{_libdir}/*.*a
 
 # tools
 install -d %{buildroot}%{_datadir}/%{name}/tools
-cp tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
+install -pm 0755 tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
 
 # database directory
 install -d %{buildroot}%{_datadir}/%{name}/
 
 
-%post -p /sbin/ldconfig
-
-%postun -p /sbin/ldconfig
-
-
-%clean
-rm -rf %{buildroot}
-
 %files
-%defattr(644,root,root,755)
+%license COPYING LICENSE.TXT
 
-%doc AUTHORS ChangeLog COPYING README.md LICENSE.TXT NEWS INSTALL LICENSE.TXT
+%doc AUTHORS ChangeLog README.md NEWS
 
-%attr(755,-,-) %{_libdir}/*.so*
+%{_libdir}/libIP2Location.so.1
+%{_libdir}/libIP2Location.so.1.0.0
 
-%attr(755,-,-) %{_datadir}/%{name}/tools/*
+%{_datadir}/%{name}/tools/
 
 %dir %{_datadir}/%{name}/
 
 
 %files devel
-%defattr(-,root,root)
-%{_includedir}/*
+%{_includedir}/IP2Loc*.h
+%{_libdir}/libIP2Location.so
 
 %doc Developers_Guide.txt
 
 
 %changelog
+* Fri Aug 28 2020 Peter Bieringer <pb@bieringer.de>
+- fix spec file according to BZ#1873302
+
+* Sat Oct  5 2019 Peter Bieringer <pb@bieringer.de> - 8.0.9-5
+- update version to 8.0.9
+
 * Sun Feb 26 2017 Peter Bieringer <pb@bieringer.de> - 8.0.4-5
 - update to 8.0.4
 - add some fixes related to move to github
diff --git a/libIP2Location/IP2Loc_DBInterface.c b/libIP2Location/IP2Loc_DBInterface.c
index 647ea69..2130e99 100644
--- a/libIP2Location/IP2Loc_DBInterface.c
+++ b/libIP2Location/IP2Loc_DBInterface.c
@@ -271,9 +271,13 @@ uint32_t IP2Location_read32(FILE *handle, uint32_t position)
     {
         fseek(handle, position-1, 0);
         temp = fread(&byte1, 1, 1, handle);
+	if (temp == 0) { return 0; };
         temp = fread(&byte2, 1, 1, handle);
+	if (temp == 0) { return 0; };
         temp = fread(&byte3, 1, 1, handle);
+	if (temp == 0) { return 0; };
         temp = fread(&byte4, 1, 1, handle);
+	if (temp == 0) { return 0; };
     }
     else
     {
@@ -295,6 +299,7 @@ uint8_t IP2Location_read8(FILE *handle, uint32_t position)
     {
         fseek(handle, position-1, 0);
         temp = fread(&ret, 1, 1, handle);
+	if (temp == 0) { return 0; };
     }
     else
     {
@@ -309,13 +314,16 @@ char *IP2Location_readStr(FILE *handle, uint32_t position)
     char *str = 0;
     uint8_t *cache_shm = cache_shm_ptr;
     size_t temp;
+
     if (DB_access_type == IP2LOCATION_FILE_IO && handle != NULL)
     {
         fseek(handle, position, 0);
         temp = fread(&size, 1, 1, handle);
+	if (temp == 0) { return ""; };
         str = (char *)malloc(size+1);
         memset(str, 0, size+1);
         temp = fread(str, size, 1, handle);
+	if (temp == 0) { return ""; };
     }
     else
     {
@@ -341,9 +349,13 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
     {
         fseek(handle, position-1, 0);
         temp = fread(p+3, 1, 1, handle);
+	if (temp == 0) { return 0.0; };
         temp = fread(p+2, 1, 1, handle);
+	if (temp == 0) { return 0.0; };
         temp = fread(p+1, 1, 1, handle);
+	if (temp == 0) { return 0.0; };
         temp = fread(p,   1, 1, handle);
+	if (temp == 0) { return 0.0; };
     }
     else
     {
@@ -357,6 +369,7 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
     {
         fseek(handle, position-1, 0);
         temp = fread(&ret, 4, 1, handle);
+	if (temp == 0) { return 0.0; };
     }
     else
     {
@@ -365,5 +378,3 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
 #endif
     return ret;
 }
-
-
diff --git a/libIP2Location/IP2Location.c b/libIP2Location/IP2Location.c
index fbe7fe0..a036580 100644
--- a/libIP2Location/IP2Location.c
+++ b/libIP2Location/IP2Location.c
@@ -61,7 +61,6 @@ uint8_t USAGETYPE_POSITION[25]           = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 static int IP2Location_initialize(IP2Location *loc);
 static IP2LocationRecord *IP2Location_new_record();
 static uint32_t IP2Location_ip2no(char* ip);
-static struct in6_addr_local  IP2Location_ipv6_to_no(char* ipaddr);
 static int IP2Location_ip_is_ipv4 (char* ipaddr);
 static int IP2Location_ip_is_ipv6 (char* ipaddr);
 static IP2LocationRecord *IP2Location_get_record(IP2Location *loc, char *ip, uint32_t mode);
@@ -151,8 +150,8 @@ static int IP2Location_initialize(IP2Location *loc)
     loc->ipv6databasecount  = IP2Location_read32(loc->filehandle, 14);
     loc->ipv6databaseaddr   = IP2Location_read32(loc->filehandle, 18);
 
-    loc->ipv4indexbaseaddr 	= IP2Location_read32(loc->filehandle, 22);
-    loc->ipv6indexbaseaddr	= IP2Location_read32(loc->filehandle, 26);
+    loc->ipv4indexbaseaddr     = IP2Location_read32(loc->filehandle, 22);
+    loc->ipv6indexbaseaddr    = IP2Location_read32(loc->filehandle, 26);
 
     return 0;
 }
@@ -381,47 +380,77 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
 
     if ((mode & COUNTRYSHORT) && (COUNTRY_POSITION[dbtype] != 0))
     {
-        record->country_short = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1)));
+        if (!record->country_short)
+        {
+            record->country_short = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->country_short = strdup(NOT_SUPPORTED);
+        if (!record->country_short)
+        {
+            record->country_short = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & COUNTRYLONG) && (COUNTRY_POSITION[dbtype] != 0))
     {
-        record->country_long = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1))+3);
+        if (!record->country_long)
+        {
+            record->country_long = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1))+3);
+        }
     }
     else
     {
-        record->country_long = strdup(NOT_SUPPORTED);
+        if (!record->country_long)
+        {
+            record->country_long = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & REGION) && (REGION_POSITION[dbtype] != 0))
     {
-        record->region = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (REGION_POSITION[dbtype]-1)));
+        if (!record->region)
+        {
+            record->region = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (REGION_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->region = strdup(NOT_SUPPORTED);
+        if (!record->region)
+        {
+            record->region = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & CITY) && (CITY_POSITION[dbtype] != 0))
     {
-        record->city = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (CITY_POSITION[dbtype]-1)));
+        if (!record->city)
+        {
+            record->city = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (CITY_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->city = strdup(NOT_SUPPORTED);
+        if (!record->city)
+        {
+            record->city = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & ISP) && (ISP_POSITION[dbtype] != 0))
     {
-        record->isp = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ISP_POSITION[dbtype]-1)));
+        if (!record->isp)
+        {
+            record->isp = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ISP_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->isp = strdup(NOT_SUPPORTED);
+        if (!record->isp)
+        {
+            record->isp = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & LATITUDE) && (LATITUDE_POSITION[dbtype] != 0))
@@ -444,108 +473,174 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
 
     if ((mode & DOMAIN_) && (DOMAIN_POSITION[dbtype] != 0))
     {
-        record->domain = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (DOMAIN_POSITION[dbtype]-1)));
+        if (!record->domain)
+        {
+            record->domain = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (DOMAIN_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->domain = strdup(NOT_SUPPORTED);
+        if (!record->domain)
+        {
+            record->domain = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & ZIPCODE) && (ZIPCODE_POSITION[dbtype] != 0))
     {
-        record->zipcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ZIPCODE_POSITION[dbtype]-1)));
+        if (!record->zipcode)
+        {
+            record->zipcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ZIPCODE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->zipcode = strdup(NOT_SUPPORTED);
+        if (!record->zipcode)
+        {
+            record->zipcode = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & TIMEZONE) && (TIMEZONE_POSITION[dbtype] != 0))
     {
-        record->timezone = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (TIMEZONE_POSITION[dbtype]-1)));
+        if (!record->timezone)
+        {
+            record->timezone = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (TIMEZONE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->timezone = strdup(NOT_SUPPORTED);
+        if (!record->timezone)
+        {
+            record->timezone = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & NETSPEED) && (NETSPEED_POSITION[dbtype] != 0))
     {
-        record->netspeed = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (NETSPEED_POSITION[dbtype]-1)));
+        if (!record->netspeed)
+        {
+            record->netspeed = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (NETSPEED_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->netspeed = strdup(NOT_SUPPORTED);
+        if (!record->netspeed)
+        {
+            record->netspeed = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & IDDCODE) && (IDDCODE_POSITION[dbtype] != 0))
     {
-        record->iddcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (IDDCODE_POSITION[dbtype]-1)));
+        if (!record->iddcode)
+        {
+            record->iddcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (IDDCODE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->iddcode = strdup(NOT_SUPPORTED);
+        if (!record->iddcode)
+        {
+            record->iddcode = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & AREACODE) && (AREACODE_POSITION[dbtype] != 0))
     {
-        record->areacode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (AREACODE_POSITION[dbtype]-1)));
+        if (!record->areacode)
+        {
+            record->areacode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (AREACODE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->areacode = strdup(NOT_SUPPORTED);
+        if (!record->areacode)
+        {
+            record->areacode = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & WEATHERSTATIONCODE) && (WEATHERSTATIONCODE_POSITION[dbtype] != 0))
     {
-        record->weatherstationcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONCODE_POSITION[dbtype]-1)));
+        if (!record->weatherstationcode)
+        {
+            record->weatherstationcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONCODE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->weatherstationcode = strdup(NOT_SUPPORTED);
+        if (!record->weatherstationcode)
+        {
+            record->weatherstationcode = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & WEATHERSTATIONNAME) && (WEATHERSTATIONNAME_POSITION[dbtype] != 0))
     {
-        record->weatherstationname = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONNAME_POSITION[dbtype]-1)));
+        if (!record->weatherstationname)
+        {
+            record->weatherstationname = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONNAME_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->weatherstationname = strdup(NOT_SUPPORTED);
+        if (!record->weatherstationname)
+        {
+            record->weatherstationname = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & MCC) && (MCC_POSITION[dbtype] != 0))
     {
-        record->mcc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MCC_POSITION[dbtype]-1)));
+        if (!record->mcc)
+        {
+            record->mcc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MCC_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->mcc = strdup(NOT_SUPPORTED);
+        if (!record->mcc)
+        {
+            record->mcc = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & MNC) && (MNC_POSITION[dbtype] != 0))
     {
-        record->mnc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MNC_POSITION[dbtype]-1)));
+        if (!record->mnc)
+        {
+            record->mnc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MNC_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->mnc = strdup(NOT_SUPPORTED);
+        if (!record->mnc)
+        {
+            record->mnc = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & MOBILEBRAND) && (MOBILEBRAND_POSITION[dbtype] != 0))
     {
-        record->mobilebrand = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MOBILEBRAND_POSITION[dbtype]-1)));
+        if (!record->mobilebrand)
+        {
+            record->mobilebrand = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MOBILEBRAND_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->mobilebrand = strdup(NOT_SUPPORTED);
+        if (!record->mobilebrand)
+        {
+            record->mobilebrand = strdup(NOT_SUPPORTED);
+        }
     }
 
     if ((mode & ELEVATION) && (ELEVATION_POSITION[dbtype] != 0))
     {
         char *mem = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ELEVATION_POSITION[dbtype]-1)));
-	record->elevation = atof(mem);
-	free(mem);
+        record->elevation = atof(mem);
+        free(mem);
     }
     else
     {
@@ -554,11 +649,17 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
 
     if ((mode & USAGETYPE) && (USAGETYPE_POSITION[dbtype] != 0))
     {
-        record->usagetype = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (USAGETYPE_POSITION[dbtype]-1)));
+        if (!record->usagetype)
+        {
+            record->usagetype = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (USAGETYPE_POSITION[dbtype]-1)));
+        }
     }
     else
     {
-        record->usagetype = strdup(NOT_SUPPORTED);
+        if (!record->usagetype)
+        {
+            record->usagetype = strdup(NOT_SUPPORTED);
+        }
     }
     return record;
 }
@@ -658,7 +759,7 @@ static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *loc, char *ip
     {
         mid = (uint32_t)((low + high) >> 1);
         ipfrom = IP2Location_read32(handle, baseaddr + mid * dbcolumn * 4);
-        ipto 	= IP2Location_read32(handle, baseaddr + (mid + 1) * dbcolumn * 4);
+        ipto     = IP2Location_read32(handle, baseaddr + (mid + 1) * dbcolumn * 4);
 
         if ((ipno >= ipfrom) && (ipno < ipto))
         {
@@ -683,17 +784,17 @@ static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *loc, char *ip
 static IP2LocationRecord *IP2Location_get_record(IP2Location *loc, char *ipstring, uint32_t mode)
 {
     ipv_t parsed_ipv = IP2Location_parse_addr(ipstring);
-	if (parsed_ipv.ipversion == 4)
-	{
-		//process IPv4
-		return IP2Location_get_ipv4_record(loc, ipstring, mode, parsed_ipv);
-	}
+    if (parsed_ipv.ipversion == 4)
+    {
+        //process IPv4
+        return IP2Location_get_ipv4_record(loc, ipstring, mode, parsed_ipv);
+    }
     if (parsed_ipv.ipversion == 6)
     {
-		//process IPv6
+        //process IPv6
         return IP2Location_get_ipv6_record(loc, ipstring, mode, parsed_ipv);
     }
-	else
+    else
     {
         return IP2Location_bad_record(INVALID_IPV4_ADDRESS);
     }
diff --git a/libIP2Location/IP2Location.h b/libIP2Location/IP2Location.h
index b425362..34e9ada 100644
--- a/libIP2Location/IP2Location.h
+++ b/libIP2Location/IP2Location.h
@@ -56,7 +56,7 @@ extern "C" {
 #include "IP2Loc_DBInterface.h"
 
 /* API version changes only if functions are added (release) or changed (minor/major) */
-#define API_VERSION   8.0.8
+#define API_VERSION   8.0.9
 
 
 #define API_VERSION_MAJOR   8
diff --git a/test/test-IP2Location.c b/test/test-IP2Location.c
index f48eb3f..9ad08a2 100644
--- a/test/test-IP2Location.c
+++ b/test/test-IP2Location.c
@@ -38,7 +38,10 @@ int main () {
 	f = fopen("country_test_ipv4_data.txt","r");
 
 	while (fscanf(f, "%s", ipAddress) != EOF) {
-		fscanf(f, "%s", expectedCountry);
+		if (fscanf(f, "%s", expectedCountry) == EOF) {
+			printf("Unexpected EOF, input file broken: country_test_ipv6_data.txt\n");
+			return -1;
+		};
 		record = IP2Location_get_all(IP2LocationObj, ipAddress);
 		if (record != NULL)	{
 			if (strcmp(expectedCountry,record->country_short) != 0) {
@@ -86,7 +89,10 @@ int main () {
 	f = fopen("country_test_ipv6_data.txt","r");
 	
 	while (fscanf(f, "%s", ipAddress) != EOF) {
-		fscanf(f, "%s", expectedCountry);
+		if (fscanf(f, "%s", expectedCountry) == EOF) {
+			printf("Unexpected EOF, input file broken: country_test_ipv6_data.txt\n");
+			return -1;
+		};
 		record = IP2Location_get_all(IP2LocationObj, ipAddress);
 		if (strcmp(expectedCountry,record->country_short) != 0) {
 			fprintf(stdout,"Test IP Address %s (Test %d) failed. We got %s but expected %s,\n",ipAddress,test_num,record->country_short,expectedCountry);