@@ -299,6 +299,7 @@ IdentifySystem(void)
299299 char xpos [MAXFNAMELEN ];
300300 XLogRecPtr logptr ;
301301 char * dbname = NULL ;
302+ Size len ;
302303
303304 /*
304305 * Reply with a result set with one row, four columns. First col is system
@@ -380,21 +381,32 @@ IdentifySystem(void)
380381 /* Send a DataRow message */
381382 pq_beginmessage (& buf , 'D' );
382383 pq_sendint (& buf , 4 , 2 ); /* # of columns */
383- pq_sendint (& buf , strlen (sysid ), 4 ); /* col1 len */
384- pq_sendbytes (& buf , (char * ) & sysid , strlen (sysid ));
385- pq_sendint (& buf , strlen (tli ), 4 ); /* col2 len */
386- pq_sendbytes (& buf , (char * ) tli , strlen (tli ));
387- pq_sendint (& buf , strlen (xpos ), 4 ); /* col3 len */
388- pq_sendbytes (& buf , (char * ) xpos , strlen (xpos ));
389- /* send NULL if not connected to a database */
384+
385+ /* column 1: system identifier */
386+ len = strlen (sysid );
387+ pq_sendint (& buf , len , 4 );
388+ pq_sendbytes (& buf , (char * ) & sysid , len );
389+
390+ /* column 2: timeline */
391+ len = strlen (tli );
392+ pq_sendint (& buf , len , 4 );
393+ pq_sendbytes (& buf , (char * ) tli , len );
394+
395+ /* column 3: xlog position */
396+ len = strlen (xpos );
397+ pq_sendint (& buf , len , 4 );
398+ pq_sendbytes (& buf , (char * ) xpos , len );
399+
400+ /* column 4: database name, or NULL if none */
390401 if (dbname )
391402 {
392- pq_sendint (& buf , strlen (dbname ), 4 ); /* col4 len */
393- pq_sendbytes (& buf , (char * ) dbname , strlen (dbname ));
403+ len = strlen (dbname );
404+ pq_sendint (& buf , len , 4 );
405+ pq_sendbytes (& buf , (char * ) dbname , len );
394406 }
395407 else
396408 {
397- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
409+ pq_sendint (& buf , -1 , 4 );
398410 }
399411
400412 pq_endmessage (& buf );
@@ -413,6 +425,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
413425 int fd ;
414426 off_t histfilelen ;
415427 off_t bytesleft ;
428+ Size len ;
416429
417430 /*
418431 * Reply with a result set with one row, and two columns. The first col is
@@ -448,8 +461,9 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
448461 /* Send a DataRow message */
449462 pq_beginmessage (& buf , 'D' );
450463 pq_sendint (& buf , 2 , 2 ); /* # of columns */
451- pq_sendint (& buf , strlen (histfname ), 4 ); /* col1 len */
452- pq_sendbytes (& buf , histfname , strlen (histfname ));
464+ len = strlen (histfname );
465+ pq_sendint (& buf , len , 4 ); /* col1 len */
466+ pq_sendbytes (& buf , histfname , len );
453467
454468 fd = OpenTransientFile (path , O_RDONLY | PG_BINARY , 0666 );
455469 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
@@ -791,14 +808,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
791808
792809 initStringInfo (& output_message );
793810
794- slot_name = NameStr (MyReplicationSlot -> data .name );
795-
796811 if (cmd -> kind == REPLICATION_KIND_LOGICAL )
797812 {
798813 LogicalDecodingContext * ctx ;
799814
800- ctx = CreateInitDecodingContext (
801- cmd -> plugin , NIL ,
815+ ctx = CreateInitDecodingContext (cmd -> plugin , NIL ,
802816 logical_read_xlog_page ,
803817 WalSndPrepareWrite , WalSndWriteData );
804818
@@ -834,7 +848,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
834848 ReplicationSlotSave ();
835849 }
836850
837- slot_name = NameStr (MyReplicationSlot -> data .name );
838851 snprintf (xpos , sizeof (xpos ), "%X/%X" ,
839852 (uint32 ) (MyReplicationSlot -> data .confirmed_flush >> 32 ),
840853 (uint32 ) MyReplicationSlot -> data .confirmed_flush );
@@ -885,30 +898,34 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
885898 pq_sendint (& buf , 4 , 2 ); /* # of columns */
886899
887900 /* slot_name */
888- pq_sendint (& buf , strlen (slot_name ), 4 ); /* col1 len */
889- pq_sendbytes (& buf , slot_name , strlen (slot_name ));
901+ len = strlen (NameStr (MyReplicationSlot -> data .name ));
902+ pq_sendint (& buf , len , 4 ); /* col1 len */
903+ pq_sendbytes (& buf , NameStr (MyReplicationSlot -> data .name ), len );
890904
891905 /* consistent wal location */
892- pq_sendint (& buf , strlen (xpos ), 4 ); /* col2 len */
893- pq_sendbytes (& buf , xpos , strlen (xpos ));
906+ len = strlen (xpos );
907+ pq_sendint (& buf , len , 4 );
908+ pq_sendbytes (& buf , xpos , len );
894909
895- /* snapshot name */
910+ /* snapshot name, or NULL if none */
896911 if (snapshot_name != NULL )
897912 {
898- pq_sendint (& buf , strlen (snapshot_name ), 4 ); /* col3 len */
899- pq_sendbytes (& buf , snapshot_name , strlen (snapshot_name ));
913+ len = strlen (snapshot_name );
914+ pq_sendint (& buf , len , 4 );
915+ pq_sendbytes (& buf , snapshot_name , len );
900916 }
901917 else
902- pq_sendint (& buf , -1 , 4 ); /* col3 len, NULL */
918+ pq_sendint (& buf , -1 , 4 );
903919
904- /* plugin */
920+ /* plugin, or NULL if none */
905921 if (cmd -> plugin != NULL )
906922 {
907- pq_sendint (& buf , strlen (cmd -> plugin ), 4 ); /* col4 len */
908- pq_sendbytes (& buf , cmd -> plugin , strlen (cmd -> plugin ));
923+ len = strlen (cmd -> plugin );
924+ pq_sendint (& buf , len , 4 );
925+ pq_sendbytes (& buf , cmd -> plugin , len );
909926 }
910927 else
911- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
928+ pq_sendint (& buf , -1 , 4 );
912929
913930 pq_endmessage (& buf );
914931
0 commit comments