tatsuhiro-t / spdylay

The experimental SPDY protocol version 2, 3 and 3.1 implementation in C
http://tatsuhiro-t.github.io/spdylay/
MIT License
603 stars 102 forks source link

wrong format passed to printf #67

Closed snnn closed 11 years ago

snnn commented 11 years ago

int spdylay_ssl.cc:

void print_timer()
{
  timeval tv;
  get_timer(&tv);
  printf("%s[%3ld.%03ld]%s",
         ansi_esc("\033[33m"),
         tv.tv_sec, tv.tv_usec/1000,
         ansi_escend());
}

The type of "tv.tv_usec" is suseconds_t, in some platform(e.g.Linux) it is 8 bytes and some platform(e.g. Mac OS X) it is 4 bytes.

#include <iostream>
#include <sys/time.h>

#include <typeinfo>
#include <cxxabi.h>
#include <stdlib.h>

int main(){
  std::cout<<"sizeof(suseconds_t)="<<sizeof(suseconds_t)<<std::endl;

  int status;
  char *realname = abi::__cxa_demangle(typeid(suseconds_t).name(), 0, 0, &status);
  std::cout<<realname<<std::endl;
  free(realname);
  return 0;
}

$ clang++ -o t test.cpp $ ./t sizeof(suseconds_t)=4 int $ file t t: Mach-O 64-bit executable x86_64

tatsuhiro-t commented 11 years ago

Casted tv.tv_sec to (long int) in c02fefe

tatsuhiro-t commented 11 years ago

I believe the above commit fixed the issue.