Changeset 5896:aef8b3923086 in roaraudio


Ignore:
Timestamp:
04/14/13 13:55:14 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

cleanup of usage of hard coded buffer lengths. Migrated some cases to usage of sizeof()

Location:
libroar
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libroar/basic.c

    r5895 r5896  
    526526  if ( stat(ROAR_PROC_NET_DECNET, &decnet_stat) == 0 ) { 
    527527   if ( roar_socket_get_local_nodename() ) { 
    528     snprintf(user_sock, 79, "%s::%s", roar_socket_get_local_nodename(), ROAR_DEFAULT_OBJECT); 
     528    snprintf(user_sock, sizeof(user_sock)-1, "%s::%s", roar_socket_get_local_nodename(), ROAR_DEFAULT_OBJECT); 
    529529    if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_DECNET, flags, timeout) == 0 ) 
    530530     return 0; 
  • libroar/cdrom.c

    r5895 r5896  
    6363 if ( track != -1 ) { 
    6464  pos = my_pos; 
    65   snprintf(pos, 32, "%i", track); 
     65  snprintf(pos, sizeof(my_pos), "%i", track); 
    6666 } 
    6767 
  • libroar/socket.c

    r5895 r5896  
    10811081  return -1; 
    10821082 
    1083  if ( (len = snprintf(buf, 1024, "CONNECT %s:%i HTTP/1.0\r\nUser-Agent: libroar\r\n\r\n", host, port)) == -1 ) 
     1083 if ( (len = snprintf(buf, sizeof(buf), "CONNECT %s:%i HTTP/1.0\r\nUser-Agent: libroar\r\n\r\n", host, port)) == -1 ) 
    10841084  return -1; 
    10851085 
     
    10871087  return -1; 
    10881088 
    1089  while ( (len = read(fh, buf, 1024)) ) { 
    1090   if ( len == 1024 ) { // overlong lion 
     1089 while ( (len = read(fh, buf, sizeof(buf))) ) { 
     1090  if ( len == sizeof(buf) ) { // overlong lion 
    10911091   return -1; 
    10921092  } else if ( len == 2 && buf[0] == '\r' && buf[1] == '\n' ) { 
     
    11081108 char * sep; 
    11091109 char * bin_ssh; 
    1110  char   cmd[1024] = {0}, rcmd[1024] = {0}; 
     1110 char   cmd[1024] = "", rcmd[1024] = ""; 
    11111111 int    proxy_port = 22; 
    11121112 int    use_socat = 0; 
     
    11521152  if ( use_socat ) { 
    11531153   if ( *host == '/' ) { 
    1154     snprintf(rcmd, 1023, "socat stdio unix-connect:\"%s\"", host); 
     1154    snprintf(rcmd, sizeof(rcmd)-1, "socat stdio unix-connect:\"%s\"", host); 
    11551155   } else { 
    1156     snprintf(rcmd, 1023, "socat stdio tcp:\"%s\":%i", host, port); 
     1156    snprintf(rcmd, sizeof(rcmd)-1, "socat stdio tcp:\"%s\":%i", host, port); 
    11571157   } 
    11581158  } else { 
    1159    snprintf(rcmd, 1023, "$(which netcat nc 2> /dev/null | grep -v \" \" | head -n 1) \"%s\" %i", host, port); 
    1160   } 
    1161  
    1162   rcmd[1023] = 0; 
     1159   snprintf(rcmd, sizeof(rcmd)-1, "$(which netcat nc 2> /dev/null | grep -v \" \" | head -n 1) \"%s\" %i", host, port); 
     1160  } 
     1161 
     1162  rcmd[sizeof(rcmd)-1] = 0; 
    11631163 } 
    11641164 
     
    11691169  return -1; 
    11701170 
    1171  snprintf(cmd, 1023, "%s -p %i -l '%s' '%s' '%s'", bin_ssh, proxy_port, user, proxy_addr, rcmd); 
    1172  cmd[1023] = 0; 
     1171 snprintf(cmd, sizeof(cmd)-1, "%s -p %i -l '%s' '%s' '%s'", bin_ssh, proxy_port, user, proxy_addr, rcmd); 
     1172 cmd[sizeof(cmd)-1] = 0; 
    11731173 
    11741174 roar_mm_free(bin_ssh); 
  • libroar/vio_cmd.c

    r5895 r5896  
    661661  } 
    662662 
    663   snprintf(command, 1024, "%s --batch --no-verbose --quiet --passphrase-repeat 0 --passphrase-fd %i %s %s", bin_gpg, pwpipe[0], para, opts); 
     663  snprintf(command, sizeof(command), "%s --batch --no-verbose --quiet --passphrase-repeat 0 --passphrase-fd %i %s %s", bin_gpg, pwpipe[0], para, opts); 
    664664 
    665665  write(pwpipe[1], pw, strlen(pw)); 
     
    667667  close(pwpipe[1]); 
    668668 } else { 
    669   snprintf(command, 1024, "%s --no-verbose --quiet %s %s", bin_gpg, para, opts); 
     669  snprintf(command, sizeof(command), "%s --no-verbose --quiet %s %s", bin_gpg, para, opts); 
    670670 } 
    671671 
     
    701701 char buf[1024]; 
    702702 
    703  snprintf(buf, 1024, "-e -r %s", recipient); 
     703 snprintf(buf, sizeof(buf), "-e -r %s", recipient); 
    704704 return roar_vio_open_gpg(calls, dst, pw, 1, buf, options); 
    705705} 
  • libroar/vio_stream.c

    r5823 r5896  
    159159static int _roar_simple_new_stream_obj (struct roar_connection * con, struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, int dir, int mixer) { 
    160160 struct roar_libroar_config * config = roar_libroar_get_config(); 
    161  char file[80] = {0}; 
     161 char file[80] = ""; 
    162162 int fh = -1, listen = -1; 
    163163 static int count = 0; 
     
    217217 if ( sockname.type == ROAR_SOCKET_TYPE_DECNET ) { 
    218218  if ( roar_socket_get_local_nodename() ) { 
    219    snprintf(file, 24, "%s::roar$TMP%04x%02x", roar_socket_get_local_nodename(), getpid(), count++); 
     219   snprintf(file, sizeof(file), "%s::roar$TMP%04x%02x", roar_socket_get_local_nodename(), getpid(), count++); 
    220220  } else { 
    221221   return -1; 
  • libroar/vio_string.c

    r5823 r5896  
    5555 
    5656 va_start(ap, format); 
    57  ret = vsnprintf(buf, 8192, format, ap); 
     57 ret = vsnprintf(buf, sizeof(buf), format, ap); 
    5858 va_end(ap); 
    5959 
Note: See TracChangeset for help on using the changeset viewer.