~ubuntu-branches/ubuntu/trusty/unrar-nonfree/trusty-security

« back to all changes in this revision

Viewing changes to consio.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2012-02-14 22:39:32 UTC
  • mto: (1.1.15) (5.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20120214223932-p4fuhasoxpn1dj3f
ImportĀ upstreamĀ versionĀ 4.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
{
27
27
  if (MsgStream==MSG_NULL || MsgStream==MSG_ERRONLY)
28
28
    return;
29
 
  safebuf char Msg[MaxMsgSize];
 
29
  char Msg[MaxMsgSize];
30
30
  va_list argptr;
31
31
  va_start(argptr,fmt);
32
 
  vsprintf(Msg,fmt,argptr);
 
32
  vsnprintf(Msg,ASIZE(Msg),fmt,argptr);
 
33
 
 
34
  // Different vsnprintf implementation can return either -1 or >=MaxMsgSize
 
35
  // if string is truncated. So we do not check exit code and always zero
 
36
  // terminate the string for safety. It is faster than check for error.
 
37
  Msg[ASIZE(Msg)-1] = 0;
 
38
 
33
39
  RawPrint(Msg,MsgStream);
34
40
  va_end(argptr);
35
41
}
44
50
  safebuf char Msg[MaxMsgSize];
45
51
  va_list argptr;
46
52
  va_start(argptr,fmt);
47
 
  vsprintf(Msg,fmt,argptr);
 
53
  vsnprintf(Msg,ASIZE(Msg),fmt,argptr);
 
54
 
 
55
  // Different vsnprintf implementation can return either -1 or >=MaxMsgSize
 
56
  // if string is truncated. So we do not check exit code and always zero
 
57
  // terminate the string for safety. It is faster than check for error.
 
58
  Msg[ASIZE(Msg)-1] = 0;
 
59
 
48
60
  RawPrint(Msg,MSG_STDERR);
49
61
  va_end(argptr);
50
62
}
70
82
#ifdef _WIN_ALL
71
83
  CharToOemA(Msg,Msg);
72
84
 
73
 
  char OutMsg[MaxMsgSize],*OutPos=OutMsg;
74
 
  for (int I=0;Msg[I]!=0;I++)
 
85
  char OutMsg[MaxMsgSize];
 
86
  size_t OutPos=0;
 
87
  for (size_t I=0;Msg[I]!=0;I++)
75
88
  {
76
 
    if (Msg[I]=='\n' && (I==0 || Msg[I-1]!='\r'))
77
 
      *(OutPos++)='\r';
78
 
    *(OutPos++)=Msg[I];
 
89
    if (Msg[I]=='\n' && (I==0 || Msg[I-1]!='\r') && OutPos<ASIZE(OutMsg)-1)
 
90
      OutMsg[OutPos++]='\r';
 
91
    if (OutPos<ASIZE(OutMsg)-1)
 
92
      OutMsg[OutPos++]=Msg[I];
79
93
  }
80
 
  *OutPos=0;
 
94
  OutMsg[OutPos]=0;
81
95
  strcpy(Msg,OutMsg);
82
96
#endif
83
97
#if defined(_UNIX) || defined(_EMX)
84
98
  char OutMsg[MaxMsgSize],*OutPos=OutMsg;
85
 
  for (int I=0;Msg[I]!=0;I++)
 
99
  for (size_t I=0;Msg[I]!=0;I++)
86
100
    if (Msg[I]!='\r')
87
101
      *(OutPos++)=Msg[I];
88
102
  *OutPos=0;