@@ -298,6 +298,7 @@ IdentifySystem(void)
298298 char xpos [MAXFNAMELEN ];
299299 XLogRecPtr logptr ;
300300 char * dbname = NULL ;
301+ Size len ;
301302
302303 /*
303304 * Reply with a result set with one row, four columns. First col is system
@@ -379,21 +380,32 @@ IdentifySystem(void)
379380 /* Send a DataRow message */
380381 pq_beginmessage (& buf , 'D' );
381382 pq_sendint (& buf , 4 , 2 ); /* # of columns */
382- pq_sendint (& buf , strlen (sysid ), 4 ); /* col1 len */
383- pq_sendbytes (& buf , (char * ) & sysid , strlen (sysid ));
384- pq_sendint (& buf , strlen (tli ), 4 ); /* col2 len */
385- pq_sendbytes (& buf , (char * ) tli , strlen (tli ));
386- pq_sendint (& buf , strlen (xpos ), 4 ); /* col3 len */
387- pq_sendbytes (& buf , (char * ) xpos , strlen (xpos ));
388- /* send NULL if not connected to a database */
383+
384+ /* column 1: system identifier */
385+ len = strlen (sysid );
386+ pq_sendint (& buf , len , 4 );
387+ pq_sendbytes (& buf , (char * ) & sysid , len );
388+
389+ /* column 2: timeline */
390+ len = strlen (tli );
391+ pq_sendint (& buf , len , 4 );
392+ pq_sendbytes (& buf , (char * ) tli , len );
393+
394+ /* column 3: xlog position */
395+ len = strlen (xpos );
396+ pq_sendint (& buf , len , 4 );
397+ pq_sendbytes (& buf , (char * ) xpos , len );
398+
399+ /* column 4: database name, or NULL if none */
389400 if (dbname )
390401 {
391- pq_sendint (& buf , strlen (dbname ), 4 ); /* col4 len */
392- pq_sendbytes (& buf , (char * ) dbname , strlen (dbname ));
402+ len = strlen (dbname );
403+ pq_sendint (& buf , len , 4 );
404+ pq_sendbytes (& buf , (char * ) dbname , len );
393405 }
394406 else
395407 {
396- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
408+ pq_sendint (& buf , -1 , 4 );
397409 }
398410
399411 pq_endmessage (& buf );
@@ -412,6 +424,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
412424 int fd ;
413425 off_t histfilelen ;
414426 off_t bytesleft ;
427+ Size len ;
415428
416429 /*
417430 * Reply with a result set with one row, and two columns. The first col is
@@ -447,8 +460,9 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
447460 /* Send a DataRow message */
448461 pq_beginmessage (& buf , 'D' );
449462 pq_sendint (& buf , 2 , 2 ); /* # of columns */
450- pq_sendint (& buf , strlen (histfname ), 4 ); /* col1 len */
451- pq_sendbytes (& buf , histfname , strlen (histfname ));
463+ len = strlen (histfname );
464+ pq_sendint (& buf , len , 4 ); /* col1 len */
465+ pq_sendbytes (& buf , histfname , len );
452466
453467 fd = OpenTransientFile (path , O_RDONLY | PG_BINARY , 0666 );
454468 if (fd < 0 )
@@ -674,6 +688,7 @@ StartReplication(StartReplicationCmd *cmd)
674688 {
675689 char tli_str [11 ];
676690 char startpos_str [8 + 1 + 8 + 1 ];
691+ Size len ;
677692
678693 snprintf (tli_str , sizeof (tli_str ), "%u" , sendTimeLineNextTLI );
679694 snprintf (startpos_str , sizeof (startpos_str ), "%X/%X" ,
@@ -710,11 +725,13 @@ StartReplication(StartReplicationCmd *cmd)
710725 pq_beginmessage (& buf , 'D' );
711726 pq_sendint (& buf , 2 , 2 ); /* number of columns */
712727
713- pq_sendint (& buf , strlen (tli_str ), 4 ); /* length */
714- pq_sendbytes (& buf , tli_str , strlen (tli_str ));
728+ len = strlen (tli_str );
729+ pq_sendint (& buf , len , 4 ); /* length */
730+ pq_sendbytes (& buf , tli_str , len );
715731
716- pq_sendint (& buf , strlen (startpos_str ), 4 ); /* length */
717- pq_sendbytes (& buf , startpos_str , strlen (startpos_str ));
732+ len = strlen (startpos_str );
733+ pq_sendint (& buf , len , 4 ); /* length */
734+ pq_sendbytes (& buf , startpos_str , len );
718735
719736 pq_endmessage (& buf );
720737 }
@@ -762,10 +779,10 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
762779static void
763780CreateReplicationSlot (CreateReplicationSlotCmd * cmd )
764781{
765- const char * slot_name ;
766782 const char * snapshot_name = NULL ;
767783 char xpos [MAXFNAMELEN ];
768784 StringInfoData buf ;
785+ Size len ;
769786
770787 Assert (!MyReplicationSlot );
771788
@@ -790,14 +807,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
790807
791808 initStringInfo (& output_message );
792809
793- slot_name = NameStr (MyReplicationSlot -> data .name );
794-
795810 if (cmd -> kind == REPLICATION_KIND_LOGICAL )
796811 {
797812 LogicalDecodingContext * ctx ;
798813
799- ctx = CreateInitDecodingContext (
800- cmd -> plugin , NIL ,
814+ ctx = CreateInitDecodingContext (cmd -> plugin , NIL ,
801815 logical_read_xlog_page ,
802816 WalSndPrepareWrite , WalSndWriteData );
803817
@@ -825,7 +839,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
825839 ReplicationSlotPersist ();
826840 }
827841
828- slot_name = NameStr (MyReplicationSlot -> data .name );
829842 snprintf (xpos , sizeof (xpos ), "%X/%X" ,
830843 (uint32 ) (MyReplicationSlot -> data .confirmed_flush >> 32 ),
831844 (uint32 ) MyReplicationSlot -> data .confirmed_flush );
@@ -876,30 +889,34 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
876889 pq_sendint (& buf , 4 , 2 ); /* # of columns */
877890
878891 /* slot_name */
879- pq_sendint (& buf , strlen (slot_name ), 4 ); /* col1 len */
880- pq_sendbytes (& buf , slot_name , strlen (slot_name ));
892+ len = strlen (NameStr (MyReplicationSlot -> data .name ));
893+ pq_sendint (& buf , len , 4 ); /* col1 len */
894+ pq_sendbytes (& buf , NameStr (MyReplicationSlot -> data .name ), len );
881895
882896 /* consistent wal location */
883- pq_sendint (& buf , strlen (xpos ), 4 ); /* col2 len */
884- pq_sendbytes (& buf , xpos , strlen (xpos ));
897+ len = strlen (xpos );
898+ pq_sendint (& buf , len , 4 );
899+ pq_sendbytes (& buf , xpos , len );
885900
886- /* snapshot name */
901+ /* snapshot name, or NULL if none */
887902 if (snapshot_name != NULL )
888903 {
889- pq_sendint (& buf , strlen (snapshot_name ), 4 ); /* col3 len */
890- pq_sendbytes (& buf , snapshot_name , strlen (snapshot_name ));
904+ len = strlen (snapshot_name );
905+ pq_sendint (& buf , len , 4 );
906+ pq_sendbytes (& buf , snapshot_name , len );
891907 }
892908 else
893- pq_sendint (& buf , -1 , 4 ); /* col3 len, NULL */
909+ pq_sendint (& buf , -1 , 4 );
894910
895- /* plugin */
911+ /* plugin, or NULL if none */
896912 if (cmd -> plugin != NULL )
897913 {
898- pq_sendint (& buf , strlen (cmd -> plugin ), 4 ); /* col4 len */
899- pq_sendbytes (& buf , cmd -> plugin , strlen (cmd -> plugin ));
914+ len = strlen (cmd -> plugin );
915+ pq_sendint (& buf , len , 4 );
916+ pq_sendbytes (& buf , cmd -> plugin , len );
900917 }
901918 else
902- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
919+ pq_sendint (& buf , -1 , 4 );
903920
904921 pq_endmessage (& buf );
905922
0 commit comments