Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 4049)
+++ roard/roard.c	(revision 4052)
@@ -1093,4 +1093,6 @@
 // MAIN:
 
+#define _CKHAVEARGS(x) if ( (i + (x)) >= argc ) { ROAR_ERR("Option requires more arguments."); return 70; }
+
 #ifdef ROAR_HAVE_MAIN_ARGS
 int main (int argc, char * argv[]) {
@@ -1349,4 +1351,5 @@
    realtime++;
   } else if ( strcmp(k, "--chroot") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_HAVE_CHROOT
    chrootdir = argv[++i];
@@ -1368,6 +1371,8 @@
 #endif
   } else if ( strcmp(k, "--location") == 0 ) {
+   _CKHAVEARGS(1);
    g_config->location = argv[++i];
   } else if ( strcmp(k, "--pidfile") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef SUPPORT_PIDFILE
    pidfile = argv[++i];
@@ -1385,4 +1390,5 @@
 
   } else if ( strcmp(k, "--plugin-load") == 0 ) {
+   _CKHAVEARGS(1);
    if ( plugins_load(argv[++i]) == -1 ) {
     ROAR_ERR("Can not load plugin");
@@ -1394,11 +1400,15 @@
 
   } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
+   _CKHAVEARGS(1);
    sa.rate = atoi(argv[++i]);
   } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
+   _CKHAVEARGS(1);
    sa.bits = atoi(argv[++i]);
   } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
+   _CKHAVEARGS(1);
    sa.channels = atoi(argv[++i]);
 
   } else if ( strcmp(k, "--aiprofile") == 0 ) {
+   _CKHAVEARGS(1);
    if ( roar_profile2info(&sa, argv[++i]) == -1 ) {
     ROAR_ERR("Unknown audio profile: %s", argv[i]);
@@ -1408,4 +1418,5 @@
 
   } else if ( strcmp(k, "--stream-flags") == 0 ) {
+   _CKHAVEARGS(1);
    if ( update_stream_flags(argv[++i]) == -1 ) {
     ROAR_ERR("Can not set stream flags");
@@ -1414,4 +1425,5 @@
 
   } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
+   _CKHAVEARGS(1);
    driver = argv[++i];
    if ( strcmp(driver, "list") == 0 ) {
@@ -1421,6 +1433,8 @@
    }
   } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
+   _CKHAVEARGS(1);
    device = argv[++i];
   } else if ( strcmp(k, "-dO") == 0 ) {
+   _CKHAVEARGS(1);
    opts = argv[++i];
   } else if ( strcmp(k, "--list-driver") == 0 ) {
@@ -1429,8 +1443,11 @@
 
   } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
+   _CKHAVEARGS(1);
    o_drv  = argv[++i];
   } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
+   _CKHAVEARGS(1);
    o_dev  = argv[++i];
   } else if ( strcmp(k, "-oO") == 0 ) {
+   _CKHAVEARGS(1);
    o_opts = argv[++i];
   } else if ( strcmp(k, "-oP") == 0 ) {
@@ -1444,26 +1461,34 @@
 
   } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_SOURCES
    s_drv = argv[++i];
 #else
    ROAR_ERR("main(*): No support for sources compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "-S") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_SOURCES
    s_dev = argv[++i];
 #else
    ROAR_ERR("main(*): No support for sources compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "-sO") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_SOURCES
    s_opt = argv[++i];
 #else
    ROAR_ERR("main(*): No support for sources compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "-sC") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_SOURCES
    s_con = argv[++i];
 #else
    ROAR_ERR("main(*): No support for sources compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "-sP") == 0 ) {
@@ -1494,17 +1519,22 @@
 
   } else if ( strcmp(k, "--light-channels") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_LIGHT
    light_channels = atoi(argv[++i]);
 #else
    ROAR_WARN("main(*): no light subsystem compiled in");
+   i++;
 #endif
 
   } else if ( strcmp(k, "--rds-pi") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_RDTCS
    g_rdtcs.rds.pi = atoi(argv[++i]);
 #else
    ROAR_WARN("main(*): no RDTCS subsystem compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "--rds-ps") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_RDTCS
    if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) {
@@ -1514,6 +1544,8 @@
 #else
    ROAR_WARN("main(*): no RDTCS subsystem compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "--rds-pty") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_RDTCS
    if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) {
@@ -1523,4 +1555,5 @@
 #else
    ROAR_WARN("main(*): no RDTCS subsystem compiled in");
+   i++;
 #endif
   } else if ( strcmp(k, "--rds-tp") == 0 ) {
@@ -1557,4 +1590,5 @@
 #endif
   } else if ( strcmp(k, "--midi-console") == 0 ) {
+   _CKHAVEARGS(1);
 #ifndef ROAR_WITHOUT_DCOMP_CB
    midi_config.console_dev = argv[++i];
@@ -1562,4 +1596,5 @@
 #else
    ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
+   i++;
 #endif
 
@@ -1578,4 +1613,5 @@
 
   } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_HAVE_LIBX11
    x11display = argv[++i];
@@ -1587,4 +1623,5 @@
 
   } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
+   _CKHAVEARGS(1);
    // This is only useful in INET not UNIX mode.
 #ifdef ROAR_SUPPORT_LISTEN
@@ -1610,6 +1647,9 @@
 #endif
   } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    sock_addr = argv[++i];
+#else
+   i++;
 #endif
 
@@ -1622,4 +1662,5 @@
 #endif
   } else if ( strcmp(k, "--proto-dir") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) {
@@ -1627,18 +1668,30 @@
     return 1;
    }
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--proto-rate") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    sock_info.rate = atoi(argv[++i]);
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--proto-bits") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    sock_info.bits = atoi(argv[++i]);
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--proto-chans") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    sock_info.channels = atoi(argv[++i]);
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--proto-codec") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) {
@@ -1646,6 +1699,9 @@
     return 1;
    }
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--proto-aiprofile") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    if ( roar_profile2info(&sock_info, argv[++i]) == -1 ) {
@@ -1653,4 +1709,6 @@
     return 1;
    }
+#else
+   i++;
 #endif
   } else if ( strcmp(k, "--list-profiles") == 0 ) {
@@ -1660,4 +1718,5 @@
 #endif
   } else if ( strcmp(k, "--proto-profile") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_SUPPORT_LISTEN
    if ( get_listen_profile(argv[++i], &port, &sock_addr, &sock_type, &sock_proto, &sock_dir, &sock_info) == -1 ) {
@@ -1665,4 +1724,6 @@
     return 1;
    }
+#else
+   i++;
 #endif
 
@@ -1743,9 +1804,12 @@
 
   } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
+   _CKHAVEARGS(1);
    g_config->jumbo_mtu = atoi(argv[++i]);
 
   } else if ( strcmp(k, "-G") == 0 ) {
+   _CKHAVEARGS(1);
    sock_grp  = argv[++i];
   } else if ( strcmp(k, "-U") == 0 ) {
+   _CKHAVEARGS(1);
    sock_user = argv[++i];
 
@@ -1757,4 +1821,5 @@
 #endif
   } else if ( strcmp(k, "--client-fh") == 0 ) {
+   _CKHAVEARGS(1);
    if ( clients_new_from_fh(atoi(argv[++i]), ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 1) == -1 ) {
     ROAR_ERR("main(*): Can not set client's fh");
@@ -1762,4 +1827,5 @@
    }
   } else if ( strcmp(k, "--close-fh") == 0 ) {
+   _CKHAVEARGS(1);
 #ifdef ROAR_HAVE_IO_POSIX
    close(atoi(argv[++i]));
