@@ -331,8 +331,6 @@ namespace midb_agent {
331331int list_mail (const char *path, const std::string &folder,
332332 std::vector<MSG_UNIT> &parray, int *pnum, uint64_t *psize)
333333{
334- int last_pos;
335- int line_pos;
336334 char temp_line[512 ];
337335 char buff[256 *1025 ];
338336 struct pollfd pfd_read;
@@ -347,22 +345,23 @@ int list_mail(const char *path, const std::string &folder,
347345 return MIDB_RDWR_ERROR;
348346
349347 *psize = 0 ;
350- int count = 0 , offset = 0 , lines = -1 ;
348+ int count = 0 , lines = -1 ;
349+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
351350 BOOL b_fail = false ;
352351 while (true ) {
353352 pfd_read.fd = pback->sockd ;
354353 pfd_read.events = POLLIN|POLLPRI;
355354 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
356355 return MIDB_RDWR_ERROR;
357356 static_assert (std::size (buff) >= 256 *1024 + 1 );
358- int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
357+ auto read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
359358 if (read_len <= 0 )
360359 return MIDB_RDWR_ERROR;
361360 offset += read_len;
362361 buff[offset] = ' \0 ' ;
363362
364363 if (-1 == lines) {
365- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
364+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
366365 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
367366 continue ;
368367 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -386,7 +385,7 @@ int list_mail(const char *path, const std::string &folder,
386385 }
387386 }
388387
389- for (int i = last_pos; i < offset; ++i) {
388+ for (size_t i = last_pos; i < offset; ++i) {
390389 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
391390 count ++;
392391 continue ;
@@ -816,8 +815,6 @@ int unsubscribe_folder(const char *path, const std::string &folder, int *perrno)
816815int enum_folders (const char *path, std::vector<enum_folder_t > &pfile,
817816 int *perrno) try
818817{
819- int last_pos;
820- int line_pos;
821818 char temp_line[512 ];
822819 char buff[256 *1025 ];
823820 struct pollfd pfd_read;
@@ -829,21 +826,22 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
829826 if (write (pback->sockd , buff, length) != length)
830827 return MIDB_RDWR_ERROR;
831828
832- int count = 0 , offset = 0 , lines = -1 ;
829+ int count = 0 , lines = -1 ;
830+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
833831 while (true ) {
834832 pfd_read.fd = pback->sockd ;
835833 pfd_read.events = POLLIN|POLLPRI;
836834 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
837835 return MIDB_RDWR_ERROR;
838836 static_assert (std::size (buff) >= 256 *1024 + 1 );
839- int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
837+ auto read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
840838 if (read_len <= 0 )
841839 return MIDB_RDWR_ERROR;
842840 offset += read_len;
843841 buff[offset] = ' \0 ' ;
844842
845843 if (-1 == lines) {
846- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
844+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
847845 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
848846 continue ;
849847 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -867,7 +865,7 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
867865 }
868866 }
869867
870- for (int i = last_pos; i < offset; ++i) {
868+ for (size_t i = last_pos; i < offset; ++i) {
871869 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
872870 count ++;
873871 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -909,8 +907,6 @@ int enum_folders(const char *path, std::vector<enum_folder_t> &pfile,
909907int enum_subscriptions (const char *path, std::vector<enum_folder_t > &pfile,
910908 int *perrno) try
911909{
912- int last_pos;
913- int line_pos;
914910 char temp_line[512 ];
915911 char buff[256 *1025 ];
916912 struct pollfd pfd_read;
@@ -922,21 +918,22 @@ int enum_subscriptions(const char *path, std::vector<enum_folder_t> &pfile,
922918 if (write (pback->sockd , buff, length) != length)
923919 return MIDB_RDWR_ERROR;
924920
925- int count = 0 , offset = 0 , lines = -1 ;
921+ int count = 0 , lines = -1 ;
922+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
926923 while (true ) {
927924 pfd_read.fd = pback->sockd ;
928925 pfd_read.events = POLLIN|POLLPRI;
929926 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
930927 return MIDB_RDWR_ERROR;
931928 static_assert (std::size (buff) >= 256 *1024 + 1 );
932- int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
929+ auto read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
933930 if (read_len <= 0 )
934931 return MIDB_RDWR_ERROR;
935932 offset += read_len;
936933 buff[offset] = ' \0 ' ;
937934
938935 if (-1 == lines) {
939- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
936+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
940937 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
941938 continue ;
942939 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -960,7 +957,7 @@ int enum_subscriptions(const char *path, std::vector<enum_folder_t> &pfile,
960957 }
961958 }
962959
963- for (int i = last_pos; i < offset; ++i) {
960+ for (size_t i = last_pos; i < offset; ++i) {
964961 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
965962 count ++;
966963 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -1144,8 +1141,6 @@ static unsigned int di_to_flagbits(const Json::Value &jv)
11441141int list_deleted (const char *path, const std::string &folder, XARRAY *pxarray,
11451142 int *perrno)
11461143{
1147- int last_pos;
1148- int line_pos;
11491144 char *pspace;
11501145 char *pspace1;
11511146 char temp_line[512 ];
@@ -1161,22 +1156,23 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
11611156 if (write (pback->sockd , buff, length) != length)
11621157 return MIDB_RDWR_ERROR;
11631158
1164- int count = 0 , offset = 0 , lines = -1 ;
1159+ int count = 0 , lines = -1 ;
1160+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
11651161 BOOL b_format_error = false ;
11661162 while (true ) {
11671163 pfd_read.fd = pback->sockd ;
11681164 pfd_read.events = POLLIN|POLLPRI;
11691165 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
11701166 return MIDB_RDWR_ERROR;
11711167 static_assert (std::size (buff) >= 256 *1024 + 1 );
1172- int read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
1168+ auto read_len = read (pback->sockd , buff + offset, 256 *1024 - offset);
11731169 if (read_len <= 0 )
11741170 return MIDB_RDWR_ERROR;
11751171 offset += read_len;
11761172 buff[offset] = ' \0 ' ;
11771173
11781174 if (-1 == lines) {
1179- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
1175+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
11801176 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
11811177 continue ;
11821178 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -1200,7 +1196,7 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
12001196 }
12011197 }
12021198
1203- for (int i = last_pos; i < offset; ++i) {
1199+ for (size_t i = last_pos; i < offset; ++i) {
12041200 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
12051201 count ++;
12061202 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -1260,8 +1256,6 @@ int list_deleted(const char *path, const std::string &folder, XARRAY *pxarray,
12601256int fetch_simple_uid (const char *path, const std::string &folder,
12611257 const imap_seq_list &list, XARRAY *pxarray, int *perrno)
12621258{
1263- int last_pos;
1264- int line_pos;
12651259 char *pspace;
12661260 char *pspace1;
12671261 char *pspace2;
@@ -1280,21 +1274,22 @@ int fetch_simple_uid(const char *path, const std::string &folder,
12801274 if (write (pback->sockd , buff, length) != length)
12811275 return MIDB_RDWR_ERROR;
12821276
1283- int count = 0 , offset = 0 , lines = -1 ;
1277+ int count = 0 , lines = -1 ;
1278+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
12841279 BOOL b_format_error = false ;
12851280 while (true ) {
12861281 pfd_read.fd = pback->sockd ;
12871282 pfd_read.events = POLLIN|POLLPRI;
12881283 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
12891284 return MIDB_RDWR_ERROR;
1290- int read_len = read (pback->sockd , buff + offset, std::size (buff) - 1 - offset);
1285+ auto read_len = read (pback->sockd , buff + offset, std::size (buff) - 1 - offset);
12911286 if (read_len <= 0 )
12921287 return MIDB_RDWR_ERROR;
12931288 offset += read_len;
12941289 buff[offset] = ' \0 ' ;
12951290
12961291 if (-1 == lines) {
1297- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
1292+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
12981293 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
12991294 continue ;
13001295 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -1317,7 +1312,7 @@ int fetch_simple_uid(const char *path, const std::string &folder,
13171312 }
13181313 }
13191314
1320- for (int i = last_pos; i < offset; ++i) {
1315+ for (size_t i = last_pos; i < offset; ++i) {
13211316 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
13221317 count ++;
13231318 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
@@ -1388,8 +1383,6 @@ int fetch_simple_uid(const char *path, const std::string &folder,
13881383int fetch_detail_uid (const char *path, const std::string &folder,
13891384 const imap_seq_list &list, XARRAY *pxarray, int *perrno) try
13901385{
1391- int last_pos;
1392- int line_pos;
13931386 char *pspace;
13941387 char buff[64 *1025 ];
13951388 char temp_line[257 *1024 ];
@@ -1409,22 +1402,23 @@ int fetch_detail_uid(const char *path, const std::string &folder,
14091402 if (write (pback->sockd , buff, length) != length)
14101403 return MIDB_RDWR_ERROR;
14111404
1412- int count = 0 , offset = 0 , lines = -1 ;
1405+ int count = 0 , lines = -1 ;
1406+ size_t offset = 0 , last_pos = 0 , line_pos = 0 ;
14131407 BOOL b_format_error = false ;
14141408 while (true ) {
14151409 pfd_read.fd = pback->sockd ;
14161410 pfd_read.events = POLLIN|POLLPRI;
14171411 if (poll (&pfd_read, 1 , SOCKET_TIMEOUT_MS) != 1 )
14181412 return MIDB_RDWR_ERROR;
14191413 static_assert (std::size (buff) >= 64 *1024 + 1 );
1420- int read_len = read (pback->sockd , buff + offset, 64 *1024 - offset);
1414+ auto read_len = read (pback->sockd , buff + offset, 64 *1024 - offset);
14211415 if (read_len <= 0 )
14221416 return MIDB_RDWR_ERROR;
14231417 offset += read_len;
14241418 buff[offset] = ' \0 ' ;
14251419
14261420 if (-1 == lines) {
1427- for (int i = 0 ; i < offset - 1 && i < 36 ; ++i) {
1421+ for (size_t i = 0 ; i < offset - 1 && i < 36 ; ++i) {
14281422 if (buff[i] != ' \r ' || buff[i+1 ] != ' \n ' )
14291423 continue ;
14301424 if (0 == strncmp (buff, " TRUE " , 5 )) {
@@ -1447,7 +1441,7 @@ int fetch_detail_uid(const char *path, const std::string &folder,
14471441 }
14481442 }
14491443
1450- for (int i = last_pos; i < offset; ++i) {
1444+ for (size_t i = last_pos; i < offset; ++i) {
14511445 if (' \r ' == buff[i] && i < offset - 1 && ' \n ' == buff[i + 1 ]) {
14521446 count ++;
14531447 } else if (' \n ' == buff[i] && ' \r ' == buff[i - 1 ]) {
0 commit comments