Gmtselect segmentation error

Working with a gazetteer, and am encountering a segmentation fault with a command that looks like this:

gmt gmtselect t1.txt -C2k/t0.txt -fg --FORMAT_FLOAT_OUT="%.7f %.7f %s"

t0.txt consists of a single lon,lat coordinate:

-55.6 72.8833333

And t1.txt is a 10-line data set (for this example) with some unusual text strings:

-44.3166667 60.15 Aappilattoq
-44.5 60.1666667 Aappilattorq
-55.6 72.8833333 Aappilattorq
23.5333333 66.85 Aapua
35.9222222 34.3152778 Aaqabet Haïroûna
68.6480556 33.0525 `Aāqaḏāṟī Yōsufkhēl
37.2166667 35.1 Aaqâreb es Sâfi
37.2166667 35.1 Aaqârib es Sâfi
35.8 34.2166667 Aaqb el Ballâne

Output expected is:

-55.6000000 72.8833333 Aappilattorq

Instead, I get a segmentation fault. Any ideas?

ERROR: Caught signal number 11 (Segmentation fault) at
0   libsystem_platform.dylib            0x00007fff657676f2 _platform_strlen + 18
1   ???                                 0x00000000000130a0 0x0 + 77984
Stack backtrace:
0   libgmt.6.dylib                      0x000000010a55cae5 sig_handler + 581
1   libsystem_platform.dylib            0x00007fff6576ab5d _sigtramp + 29
2   ???                                 0x0000000000000000 0x0 + 0
3   libsystem_c.dylib                   0x00007fff6560e16a __vfprintf + 8812
4   libsystem_c.dylib                   0x00007fff656341c3 __v2printf + 475
5   libsystem_c.dylib                   0x00007fff65619ca2 vsprintf_l + 242
6   libsystem_c.dylib                   0x00007fff65649156 __sprintf_chk + 192
7   libgmt.6.dylib                      0x000000010a5bf76c gmt_ascii_output_no_text + 460
8   libgmt.6.dylib                      0x000000010a59144c gmtapi_put_record_fp + 108
9   libgmt.6.dylib                      0x000000010a5771a7 gmtapi_put_record_init + 519
10  libgmt.6.dylib                      0x000000010a763d6e GMT_gmtselect + 12606
11  libgmt.6.dylib                      0x000000010a57c120 GMT_Call_Module + 1696
12  gmt                                 0x000000010a552591 main + 1457
13  libdyld.dylib                       0x00007fff6557f3d5 start + 1
14  ???                                 0x0000000000000006 0x0 + 6

You are giving %s to FORMAT_FLOAT_OUT so that will crash when we try to print a double via %s.

Isn’t %s a common C specification? What FORMAT_FLOAT_OUT specification should be used when a string follows the coordinates?

%s is a common C specification, but for strings. I understand why you added it because I found a dumb bug in our parsing that prevented the trailing text from being detected in your case. Will submit a pull request shortly. There is no option to format the trailing text, it is always written with %s. After my fix I get

gmt gmtselect t1.txt -C2k/t0.txt -fg --FORMAT_FLOAT_OUT="%.7f %.7f"

-55.6000000 72.8833333 Aappilattorq

Being fixed in https://github.com/GenericMappingTools/gmt/pull/3941/files

Perfect, Paul. I was tying without the %s, and got NaNs and infs returned in the string, too. I’ll pull when you have it nailed. Thanks!

Merged into master. Give it a spin, please.

A-one! Thanks Paul, for the quick fix.

I’ve also run a larger test that involves a -Ic option! And it works, too!